Last active
April 27, 2025 00:01
-
-
Save juanbrujo/094cd486e6d77f040bff to your computer and use it in GitHub Desktop.
looping through querySelectorAll elements
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 elem = document.querySelectorAll(element) | |
// IE8+ | |
if (elem.length) { | |
for (var i = 0; i < elem.length; i++) { | |
elem[i] // iterate over this | |
} | |
} | |
// IE9+ | |
if (elem.length) { | |
[].forEach.call(elem, function(e) { | |
e // iterate over this | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I once had a headache dealing with multiple elements. Using these loops saved me. 2048