bhylu.com

Advertisements

DOM Navigation

Parent and sibling properties let you move around the node tree. Element-only properties skip whitespace text 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 id="tools">
  <li>
    Brush
  </li>
  <li>
    Tape
  </li>
</ul>
<p id="result"></p>
<script>
  const first = document.getElementById("tools").firstElementChild;
  document.getElementById("result").textContent = first.nextElementSibling.textContent;
</script>

What happens

The next element sibling contains Tape.