English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
element.nextElementSibling
var x = document.querySelector("#div-1.nextElementSibling.innerHTML;Test and See‹/›
The numbers in the table specify the first browser version that fully supports the nextElementSibling property:
Property | |||||
nextElementSibling | 2 | 3.5 | 10 | 4 | 9 |
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 |
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‹/›
HTML DOM Reference:children property
HTML DOM Reference:previousElementSibling property