How to count all child elements of a particular element using JavaScript ? Last Updated : 15 Feb, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report Given an HTML document containing some elements nested elements and the task is to count all the child elements of a particular element. It is very simple to count the number of child elements of a particular element using JavaScript. For example: If you have a parent element consisting of many child elements then you can use HTML DOM childElementCount property to count all the child elements of a particular element. Syntax node.childElementCount Example: html <h1 style="color:green">GeeksforGeeks</h1> <h3> Click the button to count all<br> children the div element </h3> <h5>Count all child elements of <ul> elements</h5> <ul id="parentID"> <li>First element</li> <li>Second element</li> <li>Third element</li> <li>Fourth element</li> </ul> <button onclick="myGeeks()"> Click Here! </button> <h5 id="GFG"></h5> <script> // This function count the child elements function myGeeks() { var count = document.getElementById( "parentID").childElementCount; document.getElementById("GFG").innerHTML = "Total Number of Child node: " + count; } </script> Output: How to count all child elements of a particular element using JavaScript ? Comment More infoAdvertise with us Next Article How to Check if an element is a child of a parent using JavaScript? _tanya_sri_ Follow Improve Article Tags : JavaScript Web Technologies Write From Home JavaScript-Questions Similar Reads How to Get the Child Element of a Parent Using JavaScript? To get a child element of a parent element in JavaScript, you can use several DOM (Document Object Model) methods, such as children, childNodes, querySelector(), or getElementById(). Here are different ways to access child elements based on the situation.1. Using children propertyThe children proper 4 min read How to Check if an element is a child of a parent using JavaScript? In this article, we are going to see the methods by which we can Check if an element is a child of a parent using JavaScript. These are the following methods: Table of Content Using the Node.contains() methodLooping through the parents of the given childUsing the hasChildNodes() methodMethod 1: Usin 5 min read How to return true if the parent element contains the child element in JavaScript ? In JavaScript, children property returns an array of those elements which are children of a given element. In order to check whether the parent element (say x) contains a child element (say y), we can use the children property to get the array of all children of x and then check whether the array ob 2 min read How to select all sibling elements of an element using jQuery ? In this article, we will discuss how to select all sibling elements of an element using jQuery. To select all sibling elements of an element, we will use the siblings() method. The siblings() method is used to find all sibling elements of the selected element. The siblings are those having the same 2 min read How to count child element using jQuery ? It is very simple to count the number of child elements in the HTML file using jQuery. For example: If you have a parent element consisting of many children elements then you can use .length or.children().length method as given below. Syntax: var len=$("#parentID").length; or var count = $("#parentI 1 min read How to filter the children of any element using jQuery ? In this article we will learn how to filter the children of any element in JQuery. JQuery is a fast and lightweight JavaScript library that simplifies the interactions between an HTML/CSS document, or more precisely the Document Object Model (DOM), and JavaScript. It is widely famous for its motto o 3 min read Like