hasChildNodes
Summary
Gets a value that indicates whether the Node has any direct Node descendant of any type.
Syntax
var hasChildNodes = element.hasChildNodes();
Return Value
Returns an object of type BooleanBoolean
Whether or not the Node contains any direct Node descendant of any type
Examples
The following 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]);
}
{{Notes_Section |Notes=If the Node contains any [[dom/Element|Element], [dom/Text|Text] or other type of nodes, they can be accessed from the childNodes collection. }}
Related specifications
- Document Object Model (DOM) Level 3 Core
- W3C Recommendation
Attributions
Mozilla Developer Network : [Node.hasChildNodes Article]
Microsoft Developer Network: [hasChildNodes() Method Article]