javascriptjqueryjquery-selectorsnested-loopsnextuntil

jQuery nested loop nextUntil selector


So I basically have the following files and html document

jQuery(function () {
jQuery(".jx_form_Annuairecommunal").click(function () {
    jQuery(this).nextUntil().find('.level3').slideToggle(300);
    return false;
});
});

my problem is that im not being able to stop the accordion effect to the next .level0.level2

My nextUntil() function doesnt end where desired and so it expands the whole accordion with all .level3 open

Thx for ur helpful answers in advance


Solution

  • Try

    jQuery(function ($) {
        $(".jx_form_Annuairecommunal").click(function () {
            $(this).nextUntil('.jx_form_Annuairecommunal:has(.level0 .level2)').find('.level3').slideToggle(300);
            return false;
        });
    });
    

    Demo: Fiddle