Posted By

adambundy on 03/01/13


Tagged

javascript jquery


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

adambundy


jQuery wrap every X elements in a set with a div


 / Published in: jQuery
 

myEls should be the selector statement for whatever elements you want to effect. The example wraps every 3.

  1. var myEls = $('.main > li');
  2. var numEls = myEls.length;
  3.  
  4. for ( i=0; i<numEls; i=i+3 ) {
  5. myEls.eq(i)
  6. .add( myEls.eq(i+1) )
  7. .add( myEls.eq(i+2) )
  8. .wrapAll('<div class="wrapper"/>');
  9. }

Report this snippet  

You need to login to post a comment.