Search code examples
jquerynextuntil

jQuery: Match elements between .class and items // Combine nextAll() and nextUntil()


I have this DOM

<div class="c">c</div>
<div class="a">match me not</div>
<div class="c">c</div>
<div class="c wrapper">c with some .wrapper</div>
<div class="a">match me!</div>
<div class="a">match me!</div>
<div class="c">c</div>
<div class="a">match me not</div>
<div class="c">c</div>

and need to match .a after .wrapper until the next .c

nextAll() matches everything after

nextUntil() only selects the last element

Test: http://jsfiddle.net/d4sSs/1/


Solution

  • USe like this way

    $(".wrapper").nextUntil('.c').filter(".a").addClass("matched");
    

    Demo