XML DOM length attribute
Definition and usage
The length property can return the number of nodes in a node list.
Syntax
nodelistObject.length
Instance
In all examples, we will use the XML file books.xml, and JavaScript functions loadXMLDoc().
The following code snippet can get the number of <title> elements in the XML document:
xmlDoc=loadXMLDoc("books.xml");
var x=xmlDoc.getElementsByTagName('title');
document.write("Number of title elements: " + x.length
;
Output:
Number of title elements: 4