我一直在嘗試檢查div中是否存在類。但它始終是產生的長度爲0。這裏是我的代碼: - 。Jquery-檢查類是否存在於Div內
<div id="accordion2" class="accordion" >
<div class="accordion-group">
<div class="accordion-heading"> <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">
<div class="align-nav arrow-active">OSTOMY PRODUCTS</div></a>
</div>
<div id="collapseOne" class="accordion-body in collapse">
<div class="accordion-inner">
<ul>
<li><a href="#">Professional Resources</a></li>
<li><a href="#">One-piece Pouching</a></li>
</ul>
</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading"> <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseTwo">
<div class="align-nav arrow-inactive">LEARNING CENTER</div>
</a> </div>
<div id="collapseTwo" class="accordion-body collapse">
<div class="accordion-inner">
<ul>
<li><a href="#">Videos</a></li>
<li><a href="#">Before Your Surgery</a></li>
</ul>
</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading"> <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseThree">
<div class="align-nav">PROFESSIONAL RESOURCES </div>
</a> </div>
</div>
<div class="accordion-group">
<div class="accordion-heading"> <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseThree">
<div class="align-nav">PROFESSIONAL RESOURCES </div>
</a> </div>
</div>
</div>
的第2格$(本).find(「手風琴體」)的長度應爲1,但它仍然顯示0.我的jQuery代碼如下: -
$('.accordion-heading').click(function() {
if($(this).find('accordion-body').exist()) {
alert('hi');
if($(this).find('.collapsed').length > 0) {
alert('hi');
//$(this).find('.accordion-toggle .align-nav').removeClass('arrow-active').addClass('arrow-inactive');
}
else {
alert('hi');
//$(this).find('.accordion-toggle .align-nav').removeClass('arrow-inactive').addClass('arrow-active');
}
}
});
我需要得到$(本).find( '手風琴體')長度= 1。 請提供解決方案。
請註明這'jQuery的version'您使用 – diEcho