Select every nth item in jQuery?

css, jquery, jquery-selectors

Solution

Try:

$("div:nth-child(3n+1)").css("clear", "both");

Problem

jQuery has the handy :even and :odd selectors for selecting the even- or odd-indexed items in a set, which I'm using to clear every other item in a series of floated boxes, as follows: ``` <div class='2up'> <div> ... </div> <div> ... </div> ... <div> ... </div> </div> ``` and ``` // Clear every 2nd block for 2-up blocks $('.2up>div:even').css("clear", "both"); ``` This works like a charm. My question: Is there a straightforward way in jQuery to select every third or fourth item, so I could do the same thing with 3-up or 4-up items?

Original source