And just as an exercise, here's the 'jQuery' way chained: $('a').filter(':lt(10)').addClass('first').end().filter(':gt(9):lt (10)').addClass('second').end().filter(':gt(19):lt(10)').addClass ('third').end().filter(':gt(29)').addClass('fourth');
Not really any speed gain though. On Feb 26, 1:21 am, mkmanning <michaell...@gmail.com> wrote: > It's possible. Here's a more traditional way: > > $('a').each(function(i,link){ > if(i<10){$(link).addClass('first');} > else if (i>9 && i<20){$(link).addClass('second');} > else if (i>19&&i<30){$(link).addClass('third');} > else if (i>29&&i<40){$(link).addClass('fourth');} > }) > > Here's a more 'jQuery' way: > $('a:lt(10)').addClass('first'); > $('a:gt(9):lt(10)').addClass('second'); > $('a:gt(19):lt(10)').addClass('third'); > $('a:gt(29):lt(10)').addClass('fourth'); > > Which is better? The first takes a little over half as long as the > second. > > On Feb 25, 10:45 pm, Nic Hubbard <nnhubb...@gmail.com> wrote: > > > I have a list of links, around 40 of them. I want to apply classes to > > groups of them. So, items 1-10 I want to apply a class to, then > > 11-20, then 21-30 and 31-40, each of these groups should have their > > own class. > > > Is something like this possible? I looked through the jQuery > > selectors and could not find a solution.