Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery group every 3rd div

I have the following structure, one outer div (#results) and about 20 divs with the class event. I want to group every 3 events and wrap a div called outer around them,

<div id="result">

    <div class="event">
        <div class="date">8 April</div> 
            <div class="eventname">my title</div>
            <div class="link">my link goes here</div>
    </div>

// lots more events here
</div>
like image 857
LeBlaireau Avatar asked Dec 22 '22 00:12

LeBlaireau


1 Answers

Try:

while ($('#result > .event').length > 0) {
    $('#result > .event:lt(3)').wrapAll('<div class="wrap"></div>')
}​​​​

http://jsfiddle.net/rxxjp/

like image 54
Yoshi Avatar answered Jan 04 '23 17:01

Yoshi