JQuery停止在课堂上切换

时间:2011-02-11 17:01:53

标签: jquery click toggle

我目前有针对无法更改的过滤器的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>

2 个答案:

答案 0 :(得分:5)

您需要nextUntil()

$(this).nextUntil("div.refinement_custom_category_section").toggle("fast");

nextAll将选择与选择器匹配的所有兄弟姐妹。

答案 1 :(得分:0)

$(".refinement_custom_category_section").click(function () {
  var $subcat = $(this).nextUntil("div.refinement_custom_category_section");
  $(this).siblings("div.refinement_filter").not($subcat).hide();
  $subcat.toggle();
});