CKTIS / JavaScript
Element.nextElementSibling — the next sibling element
Element.nextElementSibling returns the nearest following element with the same parent, or null. It skips text nodes and comments.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
element.nextElementSiblingElement.nextElementSibling is a read-only property, not a method: use element.nextElementSibling without parentheses. It returns the nearest following element with the same parent, or null if there is none.
Unlike nextSibling, it skips text nodes, including whitespace, and comments. It does not search descendants. Check that the result is not null before accessing its properties.
This is a DOM API, not a feature of ECMAScript itself; having Node 24 does not establish its availability. The example needs a DOM implementation that provides document and the DOM APIs used by the code. It can run in a browser or in Node.js with a DOM implementation such as jsdom. The created elements do not need to be attached to the document.
Examples
const parent = document.createElement('div');
const first = document.createElement('span');
const second = document.createElement('span');
second.id = 'second';
parent.appendChild(first);
parent.appendChild(document.createTextNode('\n '));
parent.appendChild(document.createComment('gap'));
parent.appendChild(second);
console.log(first.nextElementSibling === second);
console.log(first.nextElementSibling.id);
console.log(second.nextElementSibling);Result
true second null
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.