X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR BOOTSTRAP XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

HTML DOM previousSibling Property

Element Object Reference Element Object

Example

Get the id of the previous sibling of a list item:

var x = document.getElementById("item1").previousSibling.id;

The result of x will be:

item1

Try it yourself »


Definition and Usage

The previousSibling property returns the previous node of the specified node, in the same tree level.

The returned node is returned as a Node object.

This property is read-only.

Tip: Use the nextSibling property to return the next 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
previousSibling Yes Yes Yes Yes Yes


Syntax

node.previousSibling

Technical Details

Return Value: A Node object, representing the previous sibling of the node, or null if there is no previous 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.nextSibling Property

HTML DOM reference: node.nodeName Property


Element Object Reference Element Object


Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook