Last active
February 4, 2023 18:18
-
-
Save danwarfel/7d3408d7e6fe4b7c00d0bb70b5493eed to your computer and use it in GitHub Desktop.
Iterating Over Result Of getElementsByClassName Using Array forEach
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var els = document.getElementsByClassName("myclass"); // Creates an HTMLObjectList not an array. | |
Array.prototype.forEach.call(els, function(el) { | |
// Do stuff here | |
console.log(el.tagName); | |
}); | |
// Or | |
[].forEach.call(els, function (el) {...}); // Creates array on the fly. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You sir, are an amazing person! Thank you!