I have a problem regarding to jQuery. I need to count the amount of <a> tags within a div. Now this can easilly be done by using $('.classOfDiv > a').size();. But I need to count the a’s within a couple of childs of classOfDiv.
Ex.
<div class="classOfDiv">
<div class="div1">
<a href="" class="link">Link</a>
<a href="" class="link">Link</a>
<a href="" class="link">Link</a>
</div>
<div class="div2">
<a href="" class="link">Link</a>
<a href="" class="link">Link</a>
<a href="" class="link">Link</a>
</div>
<div class="div3">
<a href="" class="link">Link</a>
<a href="" class="link">Link</a>
<a href="" class="link">Link</a>
</div>
<div class="div4">
<a href="" class="link">Link</a>
<a href="" class="link">Link</a>
<a href="" class="link">Link</a>
</div>
</div>
$('.classOfDiv > a').size(); With the result of 12
Can this be done?
Thanks in advance!
Just remove the
>from the selector in order to get alladescendants of.classDiv, not just the direct ones: