Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save danwarfel/7d3408d7e6fe4b7c00d0bb70b5493eed to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

ghost commented Apr 28, 2021

Thank you!!!

@Pedr0Leite
Copy link
Copy Markdown

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