X
HOME HTML5 CSS3 JAVASCRIPT SQL PHP5 JQUERY ANGULAR BOOTSTRAP3 XML MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

HTML DOM previousSibling Property

Element Object Reference Element Object

Example

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

var x = document.getElementById("item2").previousSibling.innerHTML;

The result of x will be:

Coffee (first li)

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.

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

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