Jquery – How to Count Child Elements in Div?

Jquery – How to Count Child Elements in Div?

In this post we will give you information about Jquery – How to Count Child Elements in Div?. Hear we will give you detail about Jquery – How to Count Child Elements in Div?And how to use it also give you demo for it if it is necessary.

Hi All,

This article goes in detailed on jquery how to count elements in div. we will help you to give example of jquery count elements in div with class.

Here you will learn jquery count number of elements in div. i would like to share with you jquery number of elements in div.

Let’s see bellow simple example of count child elements in div using jquery. you can also count specific tag in div using jquery. i will give two example that will help you.

Example: Count “p tag” in Div

<!DOCTYPE html>

<html>

<head>

<title>jquery count number of elements in div - onlinecode</title>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

</head>

<body>

<h1>jquery count number of elements in div - onlinecode</h1>

<div id="myDiv">

<h1>Hi</h1>

<p>Hello 1</p>

<p>Hello 2</p>

</div>

<button >Click Me!</button>

<script>

$(document).ready(function(){

$('.btn1').click(function(){

var elementCount = $('#myDiv p').length;

alert(elementCount);

});

});

</script>

</body>

</html>

Example: Count all tag in Div

Also see:How to Count Number of Rows in Table Jquery?

<!DOCTYPE html>

<html>

<head>

<title>jquery count number of elements in div - onlinecode</title>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

</head>

<body>

<h1>jquery count number of elements in div - onlinecode</h1>

<div id="myDiv">

<h1>Hi</h1>

<p>Hello 1</p>

<p>Hello 2</p>

</div>

<button >Click Me!</button>

<script>

$(document).ready(function(){

$('.btn1').click(function(){

var elementCount = $('#myDiv *').length;

alert(elementCount);

});

});

</script>

</body>

</html>

I hope it can help you…

Hope this code and post will helped you for implement Jquery – How to Count Child Elements in Div?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

2  +  3  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US