HTML DOM Element childElementCount Property

Definition and Usage

childElementCount This property returns the number of child elements of the element.

childElementCount This property returns the same value as children.length.

childElementCount It is read-only.

Note:The return value is the number of child elements, not the number of child nodes (such as text and comment nodes).

See Also:

children Property

firstElementChild Property

lastElementChild Property

nextElementSibling Property

previousElementSibling Property

tagName Property

childNodes Property

HTML Nodes and Elements

In HTML DOM(Document Object Model), an HTML document is a collection of nodes that have (or do not have) child nodes.

Noderefers to element nodes, text nodes, and comment nodes.

ElementThe spaces between them are also text nodes.

while elements are just element nodes.

Child Node and Child Element

childNodes ReturnsChild Node(element nodes, text nodes, and comment nodes).

children ReturnsChild Element(not text and comment nodes).

Sibling and Element Sibling

Siblingare 'brothers' and 'sisters'.

Siblingare nodes that have the same parent node (in the same childNodes in the list).

Element Siblingare elements that have the same parent element (in the same children in the list).

Example

Example 1

The number of child elements of the <div> element:

let numb = document.getElementById("myDIV").childElementCount;

Try It Yourself

Example 2

childElementCount returns the same value as children.length:

let numb = document.getElementById("myDIV").children.length;

Try It Yourself

Syntax

element.childElementCount

Return Value

Type Description
Number The number of child elements of the element.

Browser Support

element.childElementCount It is a DOM Level 3 (2004) feature.

All browsers fully support it:

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Support 9-11 Support Support Support Support