Table of Contents

DOM - Sibling Manipulation

About

This page is about Sibling manipulation in the DOM

Method

insertAdjacent

What is InsertAdjacent and InsertAdjacentHTML and how to use them ? can insert at this positions:

<!-- beforebegin -->
<element>
  <!-- afterbegin -->
  text
  <!-- beforeend -->
</element>
<!-- afterend -->

Selector

See Sibling selector

nextElementSibling

<p>First</p>
<p>Second</p>
let p = document.querySelector("p");
console.log(p.nextElementSibling.innerText);

Documentation / Reference