Table of contents
- 1. Summary
- 2. Syntax
- 3. Examples
- 4. Specification
Summary
hasChildNodes returns a Boolean value indicating whether the current element has child nodes or not.
Syntax
element.hasChildNodes()
Examples
var result = element.hasChildNodes();
Next example removes the first child node inside the element with the id "foo" if foo has child nodes
var foo = document.getElementById("foo")
if (foo.hasChildNodes()) {
foo.removeChild(foo.childNodes[0]);
}
Note that element.hasChildNodes, without the parenthesises, will return the hasChildNodes Function, and not a Boolean.


Mozilla Developer Network