Skip to content

Instantly share code, notes, and snippets.

@christopher-paul-shaw
Created September 13, 2021 08:31
Show Gist options
  • Save christopher-paul-shaw/c79f0f35712f1865117120aa5e375aab to your computer and use it in GitHub Desktop.
Save christopher-paul-shaw/c79f0f35712f1865117120aa5e375aab to your computer and use it in GitHub Desktop.
Loop Over Elements in JS
let elements = document.querySelectorAll('.selector');
<!-- LEGACY -->
for (i = 0; i < elements.length; i++) {
console.log(elements[i]);
}
<!-- New -->
elements.forEach(function(element) {
console.log(element);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment