MDN self-hosted library · e01.org

Element: nextElementSibling property

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

html
<div id="div-01">Here is div-01</div>
<div id="div-02">Here is div-02</div>
js
let el = document.getElementById("div-01").nextElementSibling;
console.log("Siblings of div-01:");
while (el) {
  console.log(el.nodeName);
  el = el.nextElementSibling;
}