开发者

Number of divs with same class using jquery

How can I find the number of divs with a specific class name using jquery

like here I would like to get the result as 2 for class name "failedtest". and I also want to access them through the id of outer div (1285766787423container)

<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>


$("#1285766787423container div.failedtest").size();


var numberOfFailedDivs = $('#1285766787423container .failedtest').length;

or if you want only the div elements with this class:

var numberOfFailedDivs = $('#1285766787423container div.failedtest').length;


Try

$("#1285766787423container div.failedtest").length;


$("#1285766787423container div.failedtest").size();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜