2017-04-20 69 views
0

這裏是我的代碼 enter image description herenextUntil hasClass jQuery的

我想切換最接近類'.wdm_bundled_item''.mainClass_ň'

我曾嘗試:

jQuery('.mainClass_1').on('click', function(e){ 
     e.preventDefault(); 
     $(this).nextUntil('.codeByBilal').toggle(); 
    }); 

做工精細,只是問題是它的當我點擊時切換最後的tr'.mainClass_4'

有什麼建議嗎?與nextUntil或別的東西。 謝謝

+0

你可以給你的最後一行另一個類,並執行'.nextUntil('。codeByBilal,.otherClass')'?或者,可以找到某個類缺失的位置,例如'.nextUntil('。codeByBilal,:not(.cart_item)')' –

+0

您可以更具體地瞭解這個問題。請爲這個問題提供一個小工具。 –

回答

1

使用filter()過濾出所需類的元素。

jQuery('.mainClass_1').on('click', function(e){ 
    e.preventDefault(); 
    $(this).nextUntil('.codeByBilal').filter('.wdm_bundled_item').toggle(); 
});