开发者

jquery how to wrap every fifth element

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


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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜