Element.previousSibling (Property)

An HTML element at the same level within the document hierarchy.

Availability:

DOM level - 1
JavaScript - 1.5
JScript - 5.0
Internet Explorer - 5.0
Netscape - 6.0
Property/method value type:Element object
JavaScript syntax:-myElement.parentElement.children[anIndex]
-myElement.previousSibling
Argument list:anIndexAn enumerated position in the collection

The Element objects are instantiated as the HTML tags are parsed within the document source. They are added to several collections and can be navigated in a variety of ways.

Each Element object has an array of Element objects that are considered to be its direct descendants (that is children). This collection will not contain its children's children. All elements in this collection can be referred to by index and all siblings by means of an enumerator or for( ... in ... ) loop. However you can access them directly with this property.

Accessing the next object in the collection belonging to the parent by means of this property is more convenient than traversing back to the parent and working through the children property's collection.

The previous sibling will be the object prior to this one in the children property's collection of the same parent element.

If there is no previous sibling, then the null value will be returned.

See also:Element object, Element.firstChild, Element.lastChild, Element.nextSibling, Element.parentElement, Node.previousSibling

insert figure 0043