Start at 2. The list already has two <li> children.
Append an element.createElement("li") adds a new element child.
Read again. The property reflects the updated DOM — now 3.
Text does not count. Appending a text node would not change childElementCount.
Compatibility
Browser Support
Element.childElementCount is Baseline Widely available (MDN: across browsers since July 2015).
✓ Baseline · Widely available
Element.childElementCount
Supported in all modern browsers and long-standing engines. Safe for everyday DOM code.
99%Modern browser support
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
Android WebViewSupported · Modern WebView
Full support
Element.childElementCountExcellent
Bottom line: Universally available. Prefer it over childNodes.length when you only care about element children.
Frequently Asked Questions
It returns a read-only number: how many element children the element has. Text nodes, comments, and other non-element nodes are not counted.
No. MDN marks Element.childElementCount as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
Yes for practical use. childElementCount equals the length of the live HTMLCollection from el.children.
childNodes includes every child node (elements, text, comments). Whitespace text between tags often makes childNodes.length larger than childElementCount.
Yes. After you append or remove element children, reading childElementCount again returns the updated count.
No. It is read-only. Change the DOM with appendChild, remove, replaceChildren, and so on — then read the count again.