XML DOM hasChildNodes() method

Node object reference manual

Definition and usage

The hasChildNodes() method returns true if a node has any child nodes, otherwise it returns false.

Syntax:

nodeObject.hasChildNodes()

Example

In all examples, we will use the XML file books.xml, and JavaScript functions loadXMLDoc().

The following code snippet can return whether the <book> element has any child nodes:

xxmlDoc=loadXMLDoc("books.xml");
var x=xmlDoc.getElementsByTagName("book")[0];
document.write(x.hasChildNodes());

Output:

true

Node object reference manual