Please try this $("ul li").each(function(i){this.addClass(['','','test_css','test_css'][i%4])})
OR......you can try to use another one: $("li:even:odd, li:odd:odd").addClass("test_css"); On Fri, Oct 16, 2009 at 3:07 PM, Evgeny Bobovik <bobo...@gmail.com> wrote: > > try to use this function > <script> > function test(){ > var ind = 0; > $('ul').find('li').each(function(){ > if (ind == 2){ > $(this).css('test_css'); > ind = 0; > }else{ > ind++; > } > }); > > > } > > > </script> > > > > Gk___ > Sent from Minsk, Belarus > > > > 2009/10/16 huntspointer2009 <huntspoin...@gmail.com>: > > > > - Can someone please help me solve the following issue? > > - How can I select and apply a 'background-color' to the following > > <li></li> tags using JQuery? > > > > <ul class="item_list"> > > <li></li> > > <li></li> > > <li></li><!-- I want to select this one --> > > <li></li><!-- I want to select this one --> > > <li></li> > > <li></li> > > <li></li><!-- I want to select this one --> > > <li></li><!-- I want to select this one --> > > <li></li> > > <li></li> > > <li></li><!-- I want to select this one --> > > <li></li><!-- I want to select this one --> > > <li></li> > > <li></li> > > <li></li><!-- I want to select this one --> > > <li></li><!-- I want to select this one --> > > <li></li> > > <li></li> > > </ul> > > > > > > I've tried the following code, but it does NOT work: > > var test_css = {'background':'#000'}; > > $("ul li:nth-child(3n)").css(test_css); > > > > > > (Thank you, in advance) > > > > >