Find out how many child elements a <div> element has:
The result of x will be:
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.
Property | |||||
---|---|---|---|---|---|
childElementCount | 2.0 | 9.0 | 3.5 | 4.0 | 10.0 |
Return Value: | A Number, representing the number of child elements of an element |
---|---|
DOM Version | Core Level 3 Element Traversal |