JavaScript – Number of Child Elements of HTML Element
To get the count or number of child elements of a specific HTML Element using JavaScript, get reference to this HTML element, and read the childElementCount
property of this HTML Element.
childElementCount
property returns the number of child elements in this HTML Element.
In the following example, we will get the number of child elements of the HTML Element which is selected by id "myElement"
.
example.html
ADVERTISEMENT
There are three children for HTML element with id myElement
, namely, a <p>
, a <ul>
, and a <div>
.
Conclusion
In this JavaScript Tutorial, we learned how to get the number of child elements of an HTML Element using JavaScript.