开发者

jquery how to wrap every fifth element

开发者 https://www.devze.com 2022-12-16 03:16 出处:网络
i know i can do that in the hard way by using for loop or开发者_如何学运维 something like that but i\'m asking

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

精彩评论

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