我一直在尝试检查一个
内是否存在一个类。但它总是返回长度为0。这是我的代码:
<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>
前两个div中$(this).find('accordion-body')的长度应该为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');
}
}
});
我需要获取$(this).find('accordion-body').length = 1的值; 请提供解决方案。
jQuery 版本
。 - xkeshav