Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
  <meta name="viewport" content="width=device-width,initial-scale=1">
</head>
<body>
  <button>Test</button>
  <button>Test</button>
  <button>Test</button>
  <button>Test</button>
  <button>Test</button>
  <hr>
  <p>
    This code example shows how to iterate over a NodeList with a for-of loop.
  </p>
</body>
</html>
 
/* PREPARATION */
// one-character alias for qSA
let $ = document.querySelectorAll.bind(document);
// Make NodeList iterable (needed for Chrome and Edge)
NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
/* MAIN CODE */
let buttons = $('button');
for (let button of buttons) {
  
  button.addEventListener('click', (e) => {
    e.target.classList.toggle('funky');
  });
  
}
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
simevidaspro
0viewers