THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

HTML DOM childElementCount Property

Element Object Reference Element Object

Example

Find out how many child elements a <div> element has:

var x = document.getElementById("myDIV").childElementCount;

The result of x will be:

2
Try it Yourself »

Definition and Usage

The childElementCount property returns the number of child elements an element has.

Note: The returned value contains the number of child element nodes, not the number of all child nodes (like text and comment nodes).

This property is read-only.

Tip: Use the children property to return any child element of a specified element.

Tip: The childElementCount property will produce the same result as element.children.length.


Browser Support

The numbers in the table specify the first browser version that fully supports the property.

Property
childElementCount 2.0 9.0 3.5 4.0 10.0

Syntax

node.childElementCount

Technical Details

Return Value: A Number, representing the number of child elements of an element
DOM Version Core Level 3 Element Traversal

Element Object Reference Element Object