如何使用jquery
查找具有特定类名的div数就像这里我想得到的结果为2为类名“failedtest”。我也想通过外部div(1285766787423container)的id来访问它们
<div id="1285766787423container" class="container">
<div class="row">
<div class="cell1">
</div>
<div class="failedtest">
</div>
</div>
<div style="display: none;" class="row">
<div class="cell1">
</div>
<div class="failedtest">
</div>
</div>
<div style="display: none;" class="row">
<div class="cell1">
</div>
<div class="cell2">
</div>
</div>
<div style="display: none;" class="row">
<div class="cell1">
</div>
<div class="cell2">
</div>
</div>
</div>
<div id="1285766787423container" class="container">
<div class="row">
<div class="cell1">
</div>
<div class="failedtest">
</div>
</div>
<div style="display: none;" class="row">
<div class="cell1">
</div>
<div class="failedtest">
</div>
</div>
<div style="display: none;" class="row">
<div class="cell1">
</div>
<div class="cell2">
</div>
</div>
<div style="display: none;" class="row">
<div class="cell1">
</div>
<div class="cell2">
</div>
</div>
</div>
答案 0 :(得分:4)
var numberOfFailedDivs = $('#1285766787423container .failedtest').length;
或者如果您只想要此类的div
元素:
var numberOfFailedDivs = $('#1285766787423container div.failedtest').length;
答案 1 :(得分:4)
$("#1285766787423container div.failedtest").size();
答案 2 :(得分:2)
尝试
$("#1285766787423container div.failedtest").length;
答案 3 :(得分:0)
$("#1285766787423container div.failedtest").size();