Favorites

DOM Element.nextElementSibling Property

☕
Enjoying this site?

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

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

The nextElementSibling property returns the element immediately after an element in its parent, skipping text. previousElementSibling returns the one before.

Description

The read-only nextElementSibling and previousElementSibling properties return the neighboring elements in the parent's list of children, ignoring text and comments. They're useful for moving through a list, such as handling arrow keys in a menu.

They return null at either end of the parent's children, so check the result before using it, or wrap around to firstElementChild or lastElementChild when building a cycling list.

Comments and text between elements are skipped, so these properties keep working if the HTML formatting changes. In CSS, the + and ~ sibling combinators select the same kind of neighbouring elements.

Syntax

element.nextElementSibling
element.previousElementSibling

Value

The next (or previous) sibling element, or null if there isn't one.

Example

<ul>
  <li>One</li>
  <li class="active">Two</li>
  <li>Three</li>
</ul>
const active = document.querySelector('.active');
console.log(active.previousElementSibling.textContent);
console.log(active.nextElementSibling.textContent);
console.log(active.nextElementSibling.nextElementSibling);

Browser Support

The following information will show you the current browser support for the Element.nextElementSibling 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