Tuesday, April 10, 2012

Count divs in div with jquery

Solution for: We have several elements ( tags ) for example divs, in div or other object which can contain elements inside it with certain class or ID, and we want to count how many there are the certain elements. For example we have several divs:
<div class="div1">
 <div></div>
 <div></div>
 <div></div>
 <div></div>
 <div></div>
</div>
JQuery counter for the divs inside the div is:
$(document).ready(function()
{ 
 var divs_count = $("#div1 > div").size();
 alert(divs_count);
}