获取 jquery 中的 div 数量
Get count of divs in jquery
我有一个 div 包含其他几个 divs
像这样:
<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
个 class pan-box
。
我该怎么做?
你不需要循环。使用长度
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>
$("div.pan-box").length 将为您提供具有 class 'pan-box'
的 div 数量
我有一个 div 包含其他几个 divs
像这样:
<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
个 class pan-box
。
我该怎么做?
你不需要循环。使用长度
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>
$("div.pan-box").length 将为您提供具有 class 'pan-box'
的 div 数量