Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the count of elements using jQuery

Tags:

jquery

I have a span tag and that holds some n number of span tags.. can I get the number of span tags available with in the parent span using Jquery.

example:

<span class="x">
    <span id="1">one</span>
    <span id="2">two</span>
    <span id="3">three</span>
</span>

now i should find the count of number of span tags inside the parent span and my output is 3 according to the above scenario.

please help me..

like image 726
yrksundeep Avatar asked Oct 03 '11 08:10

yrksundeep


2 Answers

my version :)

$('span.x > span').length
like image 111
Andy Avatar answered Oct 08 '22 23:10

Andy


$("span.x").children("span").size()

Demo: http://jsfiddle.net/AZXv3/

like image 32
Shawn Chin Avatar answered Oct 08 '22 22:10

Shawn Chin