XML DOM lastChildProperty
Element object
Definition and Usage
The lastChild property returns the last child node of the selected element.
If the selected node has no child nodes, this property returns NULL.
Syntax
Tips and notes
Note:Firefox and most other browsers treat spaces or line breaks generated between nodes as text nodes, while Internet Explorer ignores whitespace text nodes generated between nodes. Therefore, in the example below, we will use a function to check the node type of the last child node.
The node type of an element node is 1. Therefore, if the first child node is not an element node, it will move to the next node and then continue checking whether this node is an element node. This process continues until the first element child node is found. With this method, we can get correct results in all browsers.
Tip:To learn more about browser differences, please visit our ... in our XML DOM tutorial.DOM browserChapter.
Example
The following code snippet usesloadXMLDoc()put "books.xmlLoad into xmlDoc, and get the last child node:
Example
The above code will output:
author = Erik T. Ray
year = 2003
price = 39.95
Try it Yourself »
Element objectother extensions