我目前有不能更改的div类。我想要一个.toggle,以便在单击一个部分时将其余部分隐藏起来,直到下一个类“ .refinement_custom_category_section”。当前它几乎可以正常工作,它只是将所有内容隐藏在该部分下方,当我只想单击该部分时将其隐藏。
<div class="refinement_custom_category_section">Find by Condition</div>
<div class="refinement_filter"><a href="">New (52)</a></div>
<div class="refinement_filter"><a href="">Used (7)</a></div>
<div class="refinement_filter"><a href="">Overstock - New (2)</a></div>
<div class="refinement_custom_category_section">Find by Section</div>
<div class="refinement_filter"><a href="">1 Section (2)</a></div>
<div class="refinement_filter"><a href="">2 Section (40)</a></div>
<div class="refinement_filter"><a href="">3 Section (19)</a></div>
<div class="refinement_custom_category_section">Find by Door Type</div>
<div class="refinement_filter"><a href="">Solid Door (34)</a></div>
<div class="refinement_filter"><a href="">Glass Door, Sliding (6)</a></div>
<div class="refinement_filter"><a href="">Glass Door, Swing (21)</a></div>
<div class="refinement_custom_category_section">Find by Exterior</div>
<div class="refinement_filter"><a href="">Black (33)</a></div>
<div class="refinement_filter"><a href="">Stainless Steel (28)</a></div>
<div class="refinement_custom_category_section">Find by Height</div>
<div class="refinement_filter"><a href="">34.5 inches (12)</a></div>
<div class="refinement_filter"><a href="">35.625 inches (16)</a></div>
<div class="refinement_filter"><a href="">35.875 inches (11)</a></div>
<div class="refinement_filter"><a href="">37 inches (20)</a></div>
<div class="refinement_filter"><a href="">38.75 inches (2)</a></div>
</div>
<script>
$(".refinement_custom_category_section").click(function () {
$(this).nextAll("div.refinement_filter").toggle("fast");
});
</script>
最佳答案
您需要nextUntil()
:
$(this).nextUntil("div.refinement_custom_category_section").toggle("fast");
nextAll
将选择与选择器匹配的所有同级。关于jquery - jQuery在类上停止切换,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4971839/