Name
XML.hasChildNodes( ) Method — check if a node has any descendants
Availability
Flash 5
Synopsis
theNode.hasChildNodes( )
Returns
A Boolean: true
if
theNode
has any children;
false
if it does not.
Description
The hasChildNodes( )
method indicates whether
any node hierarchy extends from a given node. It is synonymous with
the comparison expression:
theNode.childNodes.length > 0
If theNode
contains no subnodes,
hasChildNodes( )
returns
false
.
Example
We can use hasChildNodes( )
to determine whether
to operate on a node during node processing. For example, here we
remove the nodes below the first child of a document until the first
child has no more children:
while (myDoc.firstChild.hasChildNodes( )) { myDoc.firstChild.firstChild.removeNode( ); }
See Also
XML
.childNodes
Get ActionScript: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.