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;
})
精彩评论