hasChildNodes (DOMNode - JavaScript)

Checks if a node has children.

Defined in

DOMNode

Syntax

hasChildNodes() : boolean

Return value Description
boolean True if the current node has children; false otherwise.

Examples

This button gets the schema element of a DOM, then gets the elements at the next level if there are any.
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();
	if(schema.hasChildNodes()) {
		var element = schema.getFirstChild();
		while(element != null) {
			requestScope.y = requestScope.y +
				"\n\t" + element.getNodeName();
			element = element.getNextSibling();
		}
	} else {
		requestScope.y = requestScope.y + "\n\tNo children";
	}
} 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
	element1
	element0
If the input XML to the DOM is as follows:
<schema0/>
The display appears as follows:
Child nodes of schema0
	No children