Reputation: 532
So I found this code below which groups div's:
var theDivs= $('.testimonials');
var numOfLines= theDivs.length;
for (i=0; i< numOfLines; i=i+3){
theDivs.eq(i).add(theDivs.eq(i+1)).add(theDivs.eq(i+2)).wrapAll('<div class="slide" />') ;
}
It works lovely, but it only groups 3 divs, I'd like it to group 4.
I'm kicking myself about asking this question as I'm sure it's a very easy fix. I've tinkered with the numbers above, but just couldn't get it to work.
Greatly appreciate any assistance.
Upvotes: 0
Views: 50
Reputation: 85575
How about using lt jquery method:
$(".testimonials:lt(4)").wrapAll('<div class="slide" />');
Or using slice:
$('.testimonials').slice(0,5).wrapAll('<div class="slide" />');
Upvotes: 3
Reputation: 9313
Try these changes
var theDivs= $('.testimonials');
var numOfLines= theDivs.length;
for (i=0; i< numOfLines; i=i+4){
theDivs.eq(i).add(theDivs.eq(i+1)).add(theDivs.eq(i+2)).add(theDivs.eq(i+3)).wrapAll('<div class="slide" />') ;
}
Upvotes: 3