A Bunch of Options for Looping Over querySelectorAll NodeLists
A common need when writing vanilla JavaScript is to find a selection of elements in the DOM and loop over them. For example, finding instances of a button and attaching a click handler to them.
const buttons = document.querySelectorAll(".js-do-thing");
// There could be any number of these!
// I need to loop over them and attach a click handler.
There are SO MANY ways to go about it. Let’s go through them.
forEach
forEach is normally for arrays, and interestingly, …
The post A Bunch of Options for Looping Over querySelectorAll NodeLists appeared first on CSS-Tricks.




