How to traverse DOM elements from querySelectorAll

TL; DR: Use for...of loop

ThisquerySelectorAll()Method indocumentReturns a list of DOM elements that satisfy the selector query.

It returns a list of elements, the list is not an array, but aNodeListpurpose.

The easiest way to iterate through the results is to usefor..ofRing:

for (const item of document.querySelectorAll('.buttons')) {
  // something

Download mine for freeJavaScript beginner's manual

More browser tutorials: