bhylu.com

Advertisements

Selecting Elements

Use selectors that describe the element you need. QuerySelectorAll returns a static collection of matching nodes.

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="count"></p>
<script>
  const items = document.querySelectorAll("li");
  document.getElementById("count").textContent = items.length + " tools";
</script>

What happens

The page reports two tools.