Multi stack
Multi stack

Reputation: 321

Get count of divs in jquery

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

Answers (2)

Aswathy S
Aswathy S

Reputation: 729

$("div.pan-box").length will give you the number of divs having class 'pan-box'

Upvotes: 1

Roxoradev
Roxoradev

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

Related Questions