DOM Element.nextElementSibling Property
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.previousElementSiblingValue
The next (or previous) sibling element, or null if there isn't one.
Example
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.
Desktop





Tablets & Mobile





