Favorites

DOM Node.nextSibling Property

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Node.nextSibling
DOM Node PropertyThis property is supported by all modern browsers.
Updated 28th November 2026

The nextSibling property returns the node immediately after a node in its parent, which may be a text node. previousSibling returns the one before.

Description

The read-only nextSibling property returns the node that immediately follows this one in its parent's child list, and previousSibling the one before. Like firstChild, they can return white-space text nodes, so nextElementSibling and previousElementSibling are usually what you want.

They return null at the end and start of the parent's children, so a loop such as for (let n = parent.firstChild; n; n = n.nextSibling) visits every child node, including text and comments.

Comments count as siblings too, so markup with HTML comments between elements gives yet more nodes to skip. When you only care about elements, the element-only versions are simpler and less fragile if the HTML formatting changes.

Syntax

node.nextSibling
node.previousSibling

Value

The next (or previous) node with the same parent, or null if there isn't one.

Example

<ul>
  <li>One</li>
  <li>Two</li>
</ul>
const first = document.querySelector('li');
console.log(first.nextSibling.nodeName);
console.log(first.nextElementSibling.textContent);

Browser Support

The following information will show you the current browser support for the Node.nextSibling property. Hover over a browser icon to see the version that first introduced support for this property.

This property is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee