XML DOM » Node » lastChild

Syntax:
node.lastChild

This is a read-only property that returns the last child node of a node. If there is none, it returns null.

The lastChild property is read-only and returns the last child of a given node. If there is no such node, or the node is of a type that cannot have child nodes (see the DOM Structure Model), then it returns null.

Examples

Code:
XML:

<States>
   <State ref="FL">
      <name>Florida</name>
      <capital>Tallahassee</capital>
   </State>
   <State ref="IA">
      <name>Iowa</name>
      <capital>Des Moines</capital>
   </State>
</States>

Code (JavaScript):

var xml_doc = new ActiveXObject("Microsoft.XMLDOM");
xml_doc.async = false;
xml_doc.load("states.xml");

var l_child = xml_doc.documentElement.lastChild.text;
document.write(l_child);
Output:
Iowa Des Moines
Explanation:

This example obtains the text of the last child node of the root element of the 'states.xml' file.

Language(s): JavaScript XML