Latest web development tutorials
 

HTML DOM nextSibling Propery

< Element Object

Example

Get the HTML content of the next sibling of a list item:

var x = document.getElementById("item1").nextSibling.innerHTML;

The result of x will be:

Tea (second li)
Try it Yourself »

Definition and Usage

The nextSibling property returns the node immediately following the specified node, in the same tree level.

The returned node is returned as a Node object.

The difference between this property and nextElementSibling, is that nextSibling returns the next sibling node as an element node, a text node or a comment node, while nextElementSibling returns the next sibling node as an element node (ignores text and comment nodes).

This property is read-only.

Tip: Use the previousSibling property to return the previous node of the specified node, in the same tree level.

Tip: Use the childNodes property to return any child node of a specified node.


Browser Support

Property
nextSibling Yes Yes Yes Yes Yes

Syntax

node.nextSibling

Technical Details

Return Value: A Node object, representing the next sibling of the node, or null if there is no next sibling
DOM Version Core Level 1 Node Object

Related Pages

HTML DOM reference: node.childNodes Property

HTML DOM reference: node.firstChild Property

HTML DOM reference: node.lastChild Property

HTML DOM reference: node.parentNode Property

HTML DOM reference: node.previousSibling Property

HTML DOM reference: node.nodeName Property


< Element Object