Skip to content Skip to sidebar Skip to footer

In Jquery How Can I Wrap Multiple Elements With A Div Given That I Have A Start And End Class

Okay so here is some html. I have a few start and end classes but for the sake of this I have only added 1 of each.
 

Solution 1:

You were pretty close.... you do want wrapAll() but using the nextUntil() concept you have.

$('.start').each(function(){
    $(this).nextUntil('.end').wrapAll('<div class="wrapper">');
});

DEMO

If you need to also wrap the start and end use add() to add the start and end elements:

$('.start').each(function(){
     var $nextGroup= $(this).nextUntil('.end')
     $nextGroup.add(this).add($nextGroup.next()).wrapAll('<div class="wrapper">');
});

DEMO 2

Post a Comment for "In Jquery How Can I Wrap Multiple Elements With A Div Given That I Have A Start And End Class"