Created
September 13, 2021 08:31
-
-
Save christopher-paul-shaw/c79f0f35712f1865117120aa5e375aab to your computer and use it in GitHub Desktop.
Loop Over Elements in JS
This file contains 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
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