childElementCount property in javascript
childElementCount property is used to return the total count of the child elements within the element.
Syntax
var count = element.childElementCount;
Example Explanation
- In the above example we have created a div (idDiv), it is the parent element.
- Within the parent element, we have added two child elements (div, p).
- When the button is clicked fun_name Javascript function is called.
- In the Javascript function, first we are getting the div (document.getElementById("idDiv")) and storing in attr variable.
- Using the childElementCount property, we are getting the total number of child elements and displaying it (alert (attr.childElementCount)).