I know that this:
document.getElementsByClassName('class-1')[0].
selects the first <div>
that has the specify class.
I guess using a for()
will get through the whole array of <div>
.
Can somebody explain how to create that array ?
I will prefer plain Js.
Method getElementsByClassName()
returns a set of DOM elements that have a certain class name. Here is a canonical example of how to use the returned list of nodes:
var elements = document.getElementsByClassName("class-1");
for (var i = 0, len = elements.length; i < len; i++) {
// elements[i].style ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With