previousSibling (W3C DOM Core property)
| Version | Depr. | Static | Read-only |
|---|---|---|---|
| DOM1 | No | No | Yes |
| IE5.5+ | FF1.5+ | SA1.3+ | OP9+ |
|---|---|---|---|
| Full | Full | Full | Full |
Example
var sibling = node.previousSibling;
In the example above, if node has a sibling immediately
before it (a node of any type, which shares its parent with
node), the sibling variable will be
a reference to that node; otherwise it will be null.
So in the following HTML example, the first li
element is the previousSibling of the second, but
has no previousSibling of its own:
<h2>Shopping list</h2> <ul> <li>Beer</li> <li>More beer</li> </ul>
Actually this example is idealized, and in some browsers the first
li element may not in fact be the
previousSibling of the second; that's because
some browsers count intermediate whitespace as text nodes, and would
therefore consider the previousSibling to be
the whitespace between the </li> and
<li> tags.
For more about this behavior please see DOM Core.
Description
The node immediately before
this node (ie. both nodes have the same parent and are next to each other
in its childNodes collection), or
null if there is no such node.
This property is readonly.
Compatibility
| Internet Explorer | Firefox | Safari | Opera | |||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 5.5 | 6.0 | 7.0 | 1.5 | 2.0 | 3.0 | 1.3 | 2.0 | 3.0 | 9.0 | 9.5 |
| Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full |
No known issues.
User-contributed notes
There are no comments yet.
Add a note
To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.




