Paul, Thanks for the reply. I do not wish to use a container here, if I can help it, but I do have a unique class name to hook onto, and your solution works just fine with it. So my code became:
$('a.star:gt(' + ($("a.star").index(this)-1) + ')').removeClass ('star_selected').triggerHandler('mouseout'); I have a similar situation on the hover, but in reverse. The on hovered and all less than it need to have a class added. So that becomes: $('a.star:lt(' + ($("a.star").index(this)+1) + ')').addClass ('star_hover'); Works like a charm. Thanks again. I still am a bit surprised about how nextAll breaks the chain though. I realize nothing is returned, but we still know what $(this) is in this statement: $(this).nextAll('a').andSelf().removeClass ('star_selected').triggerHandler('mouseout'); So it is still unclear to me why andSelf is not enough to move you on down the line to removing the class and triggering the mouseout. If anyone can explain that to me, I'd appreciate it. Michael On Dec 12, 10:28 am, Paul Mills <paul.f.mi...@gmail.com> wrote: > Hi Michael, > Try this. It uses the index of the <a> within the <div> and then > removes the class from all <a> elements equal or greater than it. > The code is a bit cumbersome but I think it works. > > <div id="links"> > <a href="#" class="star_selected">lorem ipsum</a> > <a href="#" class="star_selected">lorem ipsum</a> > <a href="#" class="star_selected">lorem ipsum</a> > <a href="#" class="star_selected">lorem ipsum</a> > <a href="#" class="star_selected">lorem ipsum</a> > </div> > > $('#links a').click(function(){ > $('a:gt('+($("#links a').index(this)-1)+')').removeClass > ('star_selected'); > return false; > > }); > > Paul > > On Dec 12, 12:39 pm, Reepsy <mre...@gmail.com> wrote: > > > This might sound naive, but I expected this to work: > > > $(this).nextAll('a').andSelf().removeClass > > ('star_selected').triggerHandler('mouseout'); > > > It's from a star rating I wrote, where I have 5 <a> tags in a row. If > > you click on one it removes a class from it and all that follow it, > > and then fires the mouseout event. This works perfectly for stars 1-4, > > but fails on #5, because there is no next. But I did not expect it to > > ignore the rest of the chain. Everything after .nextAll is ignored. If > > I break this into two lines, it works fine: > > > $(this).nextAll('a').removeClass('star_selected'); > > $(this).removeClass('star_selected').triggerHandler('mouseout'); > > > But I am repeating myself with the removeClass. Can anyone see a way > > to combine these back into one statement? The mouseout has to go last. > > > Michael