Loop Over querySelectorAll Matches

PHOTO EMBED

Tue Jun 23 2020 08:44:22 GMT+0000 (Coordinated Universal Time)

Saved by @Amna #javascript

buttons.forEach((button) => {
  button.addEventListener('click', () => {
    console.log("forEach worked");
  });
});
content_copyCOPY

Not all browsers support forEach on NodeLists, but for those that do:

https://css-tricks.com/snippets/javascript/loop-queryselectorall-matches/