In this section, we will learn what the Element childElementCount property is and how to use it in JavaScript.
What is Element childElementCount Property in JavaScript?
The JavaScript Element childElementCount property is used to return the number of children that an element has.
For example, if an element has 10 direct children, then calling this property will return the value 10.
Note: this property only returns the number of `element` nodes but no other nodes like “text” or “comment”.
Element childElementCount Property Syntax:
element.childElementCount;
Element childElementCount Property Input Value
This property is read-only. That means we can only get the numbers and not set a value for it.
Element childElementCount Property Return Value
The return value of this property is the number of element nodes in the target element.
Example: using element childElementCount Property in JavaScript
See the Pen using element childElementCount Property in JavaScript by Omid Dehghan (@odchan1) on CodePen.