开发者

how to select each fourth div in collection using jQuery

开发者 https://www.devze.com 2023-03-24 13:18 出处:网络
I have gallery alike div container with many item di开发者_如何学Cvs inside. I want to select each fourth or in programming therms itemID % 4 == 0 item.

I have gallery alike div container with many item di开发者_如何学Cvs inside. I want to select each fourth or in programming therms itemID % 4 == 0 item.

How can i do that with jQuery?


$('#select_id:nth-child(4n)')

Here is a demo


By using the :nth-child selector http://api.jquery.com/nth-child-selector/


In this way:

var div = $("div:eq(3)");


You could use filter -

$('div').filter(function(index) {
    return (index + 1) % 4 === 0;
})
0

精彩评论

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