2011-05-14 4 views

답변

7

당신은 length 속성을 원하는 (그리고 태그 유형 제한해야합니다) :

$('div.class').length 
1
<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> 

2

.length는 당신이 일치하는 클래스의 목록을 줄 것이다

$('.class').length 
여기 1,515,

API

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

[jQuery로 요소 개수]의
관련 문제