How to Count the number of div inside a div using jQuery

In some situation we need to count the number of div inside a parentdiv with a selected class name. So to do this we need to use “>” selector in jQuery. How to Count the number of div inside a div using jQueryexpoundsofttechsolution How to Count the number of div inside a div using jQuery Syntax:-
("parentdiv > subdiv")
Let’s have a look at a simple example. Step 1. Foremost, create an HTML file.
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.2.min.js"> </script>

<title>Count the number of div</title>

</head>
<div id="parentdiv">

<div class="subdiv">subdiv 1</div>
<div class="subdiv">subdiv 2</div>
<div class="subdiv">subdiv 3</div>
<div class="subdiv">subdiv 4</div>

</div>

</html>
Step 2. Paste the following script inside the above code.
<script>
$(document).ready(function(){

var countdiv=$("#parentdiv > .subdiv").length;

alert("There are "+countdiv+" sub div")

});   
</script>
Finally, your code should look like this
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.2.min.js"> </script>

<title>Count the number of div</title>

</head>
<div id="parentdiv">

<div class="subdiv">subdiv 1</div>
<div class="subdiv">subdiv 2</div>
<div class="subdiv">subdiv 3</div>
<div class="subdiv">subdiv 4</div>

</div>

</html>

<script>
$(document).ready(function(){

var countdiv=$("#parentdiv > .subdiv").length;

alert("There are "+countdiv+" sub div")

});   
</script>
Output of the above code.
The output of the above code is 4. Because there are 4 div with class name “subdiv” inside parentdiv.