javascriptjquerynextuntil

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


Solution

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