Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

number of elements inside a div with jquery [duplicate]

Possible Duplicate:
get the elements number inside parent div jquery

Is it possible to get the number of elements that are inside a div?

<div id=count">
   <span></span>
   <span></span>
   <span></span>
   <span></span>
</div>

the resut should be

 4
like image 207
coiso Avatar asked Oct 28 '12 15:10

coiso


2 Answers

$('#count').children().length; // 4
like image 127
David G Avatar answered Oct 04 '22 22:10

David G


var count = $('#count > *').length;
like image 25
dfsq Avatar answered Oct 04 '22 22:10

dfsq