bhylu.com

Advertisements

DOM Node Lists

QuerySelectorAll gives a static NodeList. Convert it to an array when you need array methods such as map.

Where to run this

This example changes a document. Open it in the HTML playground, then select Run code. It runs inside a separate preview.

A practical example

HTML + JavaScript

<ul>
  <li>
    Brush
  </li>
  <li>
    Tape
  </li>
</ul>
<p id="result"></p>
<script>
  const names = Array.from(document.querySelectorAll("li"), item => item.textContent);
  document.getElementById("result").textContent = names.join(", ");
</script>

What happens

The paragraph reads Brush, Tape.