English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM nextElementSibling property

HTML DOM Element Object

nextElementSiblingThis property only returns the next sibling element node immediately following the element node (excluding text nodes, comment nodes);

If there is no next element at the same level, this property returnsnull.

ThepreviousElementSiblingproperty returns the previous element of the specified element.

ThechildrenThis property returns any child element of the specified element.

Syntax:

element.nextElementSibling
var x = document.querySelector("#div-1.nextElementSibling.innerHTML;
Test and See‹/›

Browser compatibility

The numbers in the table specify the first browser version that fully supports the nextElementSibling property:

Property
nextElementSibling23.51049

Technical Details

Return Value:A Node object representing the next sibling element of an element; if there is no next sibling, it isnull
DOM Version:DOM Level3

More Examples

Change the HTML content of the next sibling of the first DIV element:

var div = document.querySelector("#div-1)
div.nextElementSibling.innerHTML = "HELLO WORLD";
Test and See‹/›

Change the background color of the next sibling element of the first DIV element:

var div = document.querySelector("#div-1)
div.nextElementSibling.style.backgroundColor = "coral";
Test and See‹/›

Related References

HTML DOM Reference:children property

HTML DOM Reference:previousElementSibling property

HTML DOM Element Object