getLength (DOMNodeList - JavaScript)

Gets the number of nodes in the list.

Defined in

DOMNodeList

Syntax

getLength() : int

Return value Description
int The number of nodes where 0 means an empty list.

Examples

This button gets the child nodes below the schema level of a DOM where requestScope.n is the location of a document in the database.
if (requestScope.n != null
&& requestScope.n < database.getDocumentCount()
&& requestScope.n >= 0) {
	var dc = database.getAllDocuments();
	var doc = dc.getDocumentArray()[requestScope.n];
	var schema = doc.getFirstChild(); // get node below root
	requestScope.y = "Child nodes of " + schema.getNodeName();
	var list = schema.getChildNodes();
	if(list.getLength() > 0) {
		for(var i=0; i<list.getLength></list.getLength> {
			requestScope.y = requestScope.y +
				"\n\t" + list.item(i).getNodeName();
		}
	} else {
		requestScope.y = requestScope.y + "\n\tNo elements";
	}
} else {
	requestScope.y = "No such document";
}
If the input XML to the DOM is as follows:
<schema0>
  <element0>foo</element0>
  <element1>bar</element1>
</schema0>
The display appears as follows:
Child nodes of schema0
	element0
	element1