Returns the number of element nodes that are direct descendants of the current element.
Note: The childElementCount property is supported in Firefox from version 3.5 and Internet Explorer from version 9.The value returned by the childElementCount property contains the count of child element nodes, not the count of all child nodes. A node is an element node if it's nodeType is 1 (Node.ELEMENT_NODE). Text nodes and comment nodes are not element nodes.
If you need the child nodes of an element not only the number of them, use the children collection. It contains the child elements in source order.length property of the children collection in that browsers.
You can find the related objects in the Supported by objects section below.
This property is read-only.
Integer that retrieves the number of child elements.
Default: this property has no default value.
Example HTML code 1:
This example illustrates the use of the childElementCount property and the children collection:
Did you find this example helpful?
User Contributed Comments