XML DOM lastChildProperty
Document object
Definition and Usage
The lastChild property returns the last child node of the document.
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 blank 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, so if the last child node is not an element node, it moves to the previous node, and then continues to check whether this node is an element node. This process continues until the last element child 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.xml" Load into xmlDoc, and get the last child node of the document:
Example
Output:
Try it Yourself »
Try it Yourself
Get the first child node of the document
Document objectother extensions