XML DOM nextSiblingProperty
Node object
Definition and Usage
The nextSibling property returns the node immediately following an element (at the same tree level).
If no such node exists, the property returns null.
Syntax
Tips and notes
Note:Firefox and most other browsers treat empty spaces or line breaks generated between nodes as text nodes, while Internet Explorer ignores white space text nodes generated between nodes. Therefore, in the following example, we will use a function to check the node type of the next sibling node.
Element nodes have a node type of 1, so if the next sibling node is not an element node, it moves to the next node and continues checking whether that node is an element node. This process continues until the next sibling element node is found. In this way, we can get correct results in all browsers.
Tip:To learn more about browser differences, please visit ourDOM browserChapter.
Example
The following code snippet usesloadXMLDoc()put "books.xmlLoad into xmlDoc, and get the next sibling node from the first <title> element:
Example
The code above will output:
Next sibling: author = Giada De Laurentiis
Try it Yourself »
Try out Demos
previousSibling - Get the previous sibling node of a node
Node objectother extensions