9

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..

6 Answers 6

18

my version :)

$('span.x > span').length
Sign up to request clarification or add additional context in comments.

1 Comment

I prefer this over the version I posted. +1
3
$("span.x").children("span").size()

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

Comments

2

From the documentation you can use length or size(). You can chain jquery selectors with find to count the inner spans. For example,

<script>
  var n = $(".x").find("span").length;
  alert(n);
</script>

Comments

1

Try:

$("#id od 1st span").children("span").size();

I think this will help you.

Comments

0
$('.x span').length

this should work

http://jsfiddle.net/6kWdf/

Comments

-1

You could use this for example:

$('#showTotalBarcodeCnt').html($("#barcodeLabelList").find("label").length);

Thanks

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.