Number of child elements of a <div> element:
let numb = document.getElementById("myDIV").childElementCount;
Try it Yourself »
childElementCount returns the same as children.length:
let numb = document.getElementById("myDIV").children.length;
Try it Yourself »
The childElementCount
property returns the number of child elements of an element.
The childElementCount
property returns the same as children.length
.
The childElementCount
is read only.
The returned value is the number of child elements, not the number of child nodes (like text and comment nodes).
The firstElementChild property
The nextElementSibling Property
In the HTML DOM (Document Object Model), an HTML document is a collection of nodes with (or without) child nodes.
Nodes are element nodes, text nodes, and comment nodes.
Whitespace between elements are also text nodes.
Elements are only element nodes.
childNodes returns child nodes (element nodes, text nodes, and comment nodes).
children returns child elements (not text and comment nodes).
Siblings are "brothers" and "sisters".
Siblings are nodes with the same parent (in the same childNodes list).
Element Siblings are elements with the same parent (in the same children list).
element.childElementCount
Type | Description |
Number | The number of child elements of the element |
element.childElementCount
is a DOM Level 3 (2004) feature.
It is fully supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 11 |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!