HTML DOM previousElementSiblingProperty

元素对象参考手册Element Object

Examples

Returns the HTML content of the previous list option:

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

Try it Yourself »

Definition and Usage

The previousElementSibling property returns the previous sibling element of the specified element (the previous element node in the same node tree level).

The difference between the previousSibling property and the previousElementSibling property:

  • The previousSibling property returns the sibling node before the element node (including text nodes and comment nodes);
  • The previousElementSibling property only returns the sibling element node before the element node (excluding text nodes and comment nodes);

The previousElementSibling property is a read-only property.

Tip:Use nextElementSiblingproperty returns the next sibling element of the specified element.

Tip:Usechildrenproperty returns any child elements of the specified element.


Browser Support

Property
previousElementSibling 2.0 9.0 3.5 4.0 10.0

Syntax

node.previousElementSibling 

Technical Details

Return Value: A Node object, representing the previous sibling element of the element, or null if there is no previous sibling element.
DOM Version DOM 3


元素对象参考手册Element Object

Other Extensions