开发者

how to select each fourth div in collection using jQuery

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜