Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danwarfel/7d3408d7e6fe4b7c00d0bb70b5493eed to your computer and use it in GitHub Desktop.
Save danwarfel/7d3408d7e6fe4b7c00d0bb70b5493eed to your computer and use it in GitHub Desktop.
Iterating Over Result Of getElementsByClassName Using Array forEach
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.
Copy link

ghost commented Apr 28, 2021

Thank you!!!

@Pedr0Leite
Copy link

You sir, are an amazing person! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment