This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

previousSibling

Summary

Retrieves the previous child node of the parent of the node.

Property of dom/Nodedom/Node

Syntax

Note: This property is read-only.

var previousNode = node.previousSibling;

Return Value

Returns an object of type DOM NodeDOM Node

The previous child node of the parent of the node, or null if the node is the first child.

Examples

This example uses the previousSibling property to obtain the previous sibling of a list item.

<script>
// returns the list item labeled 'List Item 1'
var oSibling = document.getElementById("oList").childNodes[1].previousSibling;
</script>
<body>
 <ul id="oList">
  <li>List Item 1</li>
  <li>List Item 2</li>
  <li>List Item 3</li>
 </ul>
</body>

Related specifications

DOM Level 1
Recommendation

Attributions