开发者

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

开发者 https://www.devze.com 2023-03-06 08:03 出处:网络
Is there any way to find the number of DIV\'s dis开发者_如何学Cplayed in the browser with class=.class?

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

精彩评论

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