2011-02-11 77 views
1

切換我目前有無法更改過濾器的div類。我想要一個.toggle,所以當一個部分被點擊時,其餘部分隱藏到下一個類「.refinement_custom_category_section」。目前它幾乎可以工作,它只是隱藏了該部分下面的所有內容,當我只想在點擊時隱藏該部分。JQuery停止在類

<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> 

回答

5

您需要nextUntil()

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

nextAll將選擇選擇器匹配所有兄弟姐妹。

+0

真棒,工作非常感謝你! – ToddN 2011-02-11 17:13:43

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(); 
}); 
+0

這會隱藏一切,但在$ subcat中選擇的元素。這不是OP想要的:*當一個部分被點擊時,其餘部分被隱藏**直到**下一個課程「.refinement_custom_category_section」* – 2011-02-11 17:20:17