views:

178

answers:

1

Hello

i know i can do that in the hard way by using for loop or something like that but i'm asking

if : there is any simple way to wrap every 5 images in a long list of images

Thanks

+5  A: 

To "wrap" an image with another element:

Yup, its pretty simple:

// document.ready
$(function(){
   $("#yourList img:nth-child(5)").wrap("<div class='image-wrapper'></div>");
});

To force every fifth image onto the next line

// document.ready
$(function(){
   $("#yourList img:nth-child(5)").css('clear','left');
});

This could also be done in your CSS, but nth-child is not supported across all browsers:

#yourList img:nth-child(5){
   clear: left;
}
Doug Neiner
+1 Fast fingers!
CMS
@CMS... haha, I have to be fast when you are around answering questions :)
Doug Neiner
I don't think this is what the OP meant.. seems he's trying to wrap it down to the next line - ie. have only 5 images per line
K Prime
@K Prime, you are probably right... i'll update my answer to show both
Doug Neiner