/ Published in: jQuery
myEls should be the selector statement for whatever elements you want to effect. The example wraps every 3.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var myEls = $('.main > li'); var numEls = myEls.length; for ( i=0; i<numEls; i=i+3 ) { myEls.eq(i) .add( myEls.eq(i+1) ) .add( myEls.eq(i+2) ) .wrapAll('<div class="wrapper"/>'); }