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
Post a Comment