You are here: Reference > JavaScript > client-side > HTML DOM > properties > nextSibling

nextSibling property

Browser support:
Returns a reference to the next child of the current element's parent.
In other words, the nextSibling property returns the element that immediately follows the current element in the childNodes collection of the current element's parent.


You can find the related objects in the Supported by objects section below.
This property is read-only.

Possible values:

Returns a reference to the next sibling or null if it does not exist.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the nextSibling property:
    <script type="text/javascript">
        function GetNextNode () {
            var parentElem = document.getElementById ("myDiv");

            var firstElem = parentElem.childNodes[0];
            alert ("The value of the fisrt node: " + firstElem.innerHTML);

            var nextElem = firstElem.nextSibling;
            alert ("The value of the second node: " + nextElem.innerHTML);
    <div id="myDiv"><div>first elem</div><div>second elem</div></div>
    <button onclick="GetNextNode ()">Get next node!</button>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content