Ricardo,

Sorry, but it is a development stage I am not permitted to share. But
the markup is this (basically):

HTML (this was a select menu that gets converted to a hidden field and
5 <a> tags in an earlier step)

<input name="rating" id="the-rating" value="" type="hidden">
<a href="" id="star1" class="star" title="1 Star">1</a>
<a href="" id="star2" class="star" title="2 Stars">2</a>
<a href="" id="star3" class="star" title="3 Stars">3</a>
<a href="" id="star4" class="star" title="4 Stars">4</a>
<a href="" id="star5" class="star" title="5 Stars">5</a>

JS:

var r = $('#the-rating'); /* THE HIDDEN FIELD STORES RATING */
$('a.star').click(function(){
  $(r).val($(this).text()); /* RECORD RATING */
  $(this).nextAll('a').andSelf().removeClass
('star_selected').triggerHandler('mouseout');
  return false;
})
.hover(
  function() {
     $(this).preAll('a').andSelf().addClass('star_hover')
     $(this).nextAll('a').removeClass('star_selected');
  },
  function() {
    $(this).prevAll('a.star').andSelf().removeClass('star_hover');
    $('#star' + $(r).val()).prevAll('a.star').andSelf().addClass
('star_selected');
  }
);

This worked exactly as expected on stars 2-4. But on #5 the click
failed to add the class and fire the mouseout. I presume it is because
there is no nextAll. Likewise, on star #1 the hover failed remove the
class. Again, I presume because there is no prevAll.

Michael

On Dec 12, 11:50 am, ricardobeat <ricardob...@gmail.com> wrote:
> Do you have a test page we can look at?
>
> nextAllreturns an empty object if there is no 'next', but it doesn't
> interrupt thechain, there may be something else going on. I couldn't
> reproduce your situation here,nextAll().andSelf() returns me the
> original element.
>
> - ricardo
>
> On Dec 12, 10:39 am, 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 thechain. Everything after .nextAllis 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

Reply via email to