Bilal Hussain
Bilal Hussain

Reputation: 1011

nextUntil hasClass jQuery

Here's my code enter image description here

I want to toggle closest class '.wdm_bundled_item' on '.mainClass_n'

What I had tried :

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

Working fine, just the issue is it's toggling the last tr too when I click on '.mainClass_4'

Any suggestion please? with nextUntil or something else. Thanks

Upvotes: 0

Views: 365

Answers (1)

Dan Philip Bejoy
Dan Philip Bejoy

Reputation: 4391

Use filter() to filter out the elements with the desired class.

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

Upvotes: 2

Related Questions