Here is what I’m trying to do:
$(document).ready(function(){
$('ul li:eq(3n+1)').css({backgroundColor:'#f00'});
});
HTML
<ul>
<li>Item 1</li>
<li>Item 1</li>
<li>Item 1</li>
<li>Item 1</li>
<li>Item 1</li>
<li>Item 1</li>
<li>Item 1</li>
<li>Item 1</li>
</ul>
Because you seem to have confused jQuery’s
eq()selector with CSS’:nth-child()pseudo-selector.To use a CSS selector for this (albeit in the context of jQuery):
JS Fiddle demo
Using
filter()you can use:JS Fiddle demo.
But I can’t see how to do it with
eq()since, so far as I can see, that’s meant to return only one result (though I’ve not exhaustively read the whole jQuery API).References:
:nth-child selector().filter().