我有一个包含其他几个divs
的div:
<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>
我希望循环使用这些divs
来获得count
所有类pan-box
。
我怎么能这样做?
答案 0 :(得分:1)
你不需要循环。使用长度
console.log($(".pan-box").length);
&#13;
<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>
&#13;
答案 1 :(得分:1)
$(“div.pan-box”)。长度将为您提供具有“pan-box”类的div的数量