html - Selecting and modifying a collection of elements using pure Javascript without looping -


i'm trying select , style elements of same style and/or class. far i've found doing require looping through array of elements so:

var examples = document.getelementsbyclassname("example");  (var = 0; < examples.length; i++) {   examples[i].style.color = "cornflowerblue"; } 

is there way without having loop through these elements , individually select them index? i'm looking looking jquery equivalent:

$(".example") // chainable 

example for-loop

var examples = document.getelementsbyclassname("example");    (var = 0; < examples.length; i++) {    examples[i].style.color = "cornflowerblue";  }
<p class="example">example one</p>  <p>example two</p>  <p class="example">example three</p>  <p>example four</p>

array   .apply([], document.getelementsbyclassname("example"))   .foreach(function (elmnode) {     elmnode.style.color = "cornflowerblue";   }) ; 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -