views:

76

answers:

1

How can I use wrap around the content with the placeholder div using jQuery.

So I can turn this -

        <div class="placeholder"></div>
        <div class="content"></div>
        <div class="content"></div>
        <div class="content"></div>
        <div class="content"></div>
        <div class="placeholder"></div>
        <div class="content"></div>
        <div class="content"></div>
        <div class="placeholder"></div>
        <div class="content"></div>
        <div class="content"></div>
        <div class="content"></div>
        <div class="placeholder"></div>

Into this

        <div class="wrap">
            <div class="placeholder"></div>
            <div class="content">Abcd</div>
            <div class="content">Abcd</div>
            <div class="content">Abcd</div>
            <div class="content">Abcd</div>
        </div>
        <div class="wrap">
            <div class="placeholder"></div>
            <div class="content">Abcd</div>
            <div class="content">Abcd</div>
        </div>
        <div class="wrap">
            <div class="placeholder"></div>
            <div class="content">Abcd</div>
            <div class="content">Abcd</div>
            <div class="content">Abcd</div>
        </div>
+6  A: 

Try this with jQuery 1.4:

$('.placeholder').each(function(){
     $(this).nextUntil('.placeholder').andSelf().wrapAll('<div class="wrap" />');
});

jQuery 1.4 added the nextUntill function

PetersenDidIt