开发者

How to find the number of Divs with a certain Class JQuery?

Is there any way to find the number of DIV's dis开发者_如何学Cplayed in the browser with class=.class?

Something like this:

$('.class').Numberofobjects();

*Obviously Numberofobjects is made up.

Thanks!

Taylor


You want the length property (and make sure to constrain the tag type):

$('div.class').length


.length will give you the list of classes that match

$('.class').length

api here

http://api.jquery.com/length/


<html>
<head>
    <script type="text/javascript" src="jquery-1.6.1.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            alert($("div.a").length);
        });
    </script>
</head>
<body>
    <input type="button" id="mybutton" value="Click" />
    <div class="a">
    </div>
    <div class="a">
        <div class="a">
        </div>
    </div>
    <div class="a">
    </div>
</body>

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜