Not all browsers support forEach on NodeLists, but for those that do: buttons.forEach((button) => { button.addEventListener('click', () => { console.log("forEach worked"); }); }); bit deeper browser support. var divs = document.querySelectorAll('div'); [].forEach.call(divs, function(div) { // do whatever div.style.color = "red"; });
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter