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

previousSibling property

Browser support:
Returns a reference to the previous node of the current element's parent.
In other words, the previousSibling property returns the element that immediately precedes 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 previous child 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 previousSibling property:
    <script type="text/javascript">
        function GetNextNode () {
            var parentElem = document.getElementById ("myDiv");

            secondElem = parentElem.childNodes[1];
            alert ("The value of the second node: " + secondElem.innerHTML);

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

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content