hasChildNodes (W3C DOM Core method)

Spec
Version Depr. Static
DOM1 No No
Browser support (more…)
IE5.5+ FF1.5+ SA1.3+ OP9+
Full Full Full Full
Returns
Boolean

Example

var haschildren = node.hasChildNodes();

In the example above, the variable haschildren will have value true if node has any child nodes.

So in this next HTML example, if node were the p element then hasChildNodes would return true — it has a text node and an image inside it. But if node were the img, which has no child nodes, hasChildNodes would return false:

<p>
  Here is a big smiley face:
  <img src="bigsmiley.gif" alt="(big smile)" />
</p>

Description

Test whether a node has any child nodes; equivalent to evaluating whether the childNodes collection has a length greater than zero.

Return value

Returns true if this node has any children, otherwise false

Compatibility

Internet Explorer Firefox Safari Opera
5.5 6.0 7.0 1.5 2.0 3.0 1.3 2.0 3.0 9.0 9.5
Full Full Full Full Full Full Full Full Full Full Full

No known issues.

User-contributed notes

There are no comments yet.

Related Products