Reputation: 321
I have a div containing several other divs
like this:
<div class="col-md-12 col-sm-12 no-pad offersContainer">
<div class="pan-box specialoffers"></div>
<div class="pan-box offers"></div>
<div class="pan-box offers"></div>
</div>
I want to loop through these divs
to get count
of all having class pan-box
.
How can I do this?
Upvotes: 1
Views: 49
Reputation: 729
$("div.pan-box").length will give you the number of divs having class 'pan-box'
Upvotes: 1
Reputation: 893
You don't need a loop. Use length
console.log($(".pan-box").length);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="col-md-12 col-sm-12 no-pad offersContainer">
<div class="pan-box specialoffers"></div>
<div class="pan-box offers"></div>
<div class="pan-box offers"></div>
</div>
Upvotes: 1