I've discovered the cause of the problem... slice() and eq() require
the arguments to be integers, and do not properly handle strings which
happen to only hold integers.

eq(3) != eq('3')

In my example, my problem is solved by doing the following:

 
stars.eq(parseInt(averageIndex)).addClass('on').children('a').css('width',
percent + "%");

Which forces an integer value to be passed to eq().

I'm not sure that this is a bug, but it is certainly not very
friendly...

On Sep 24, 4:38 pm, Jim Spath <[EMAIL PROTECTED]> wrote:
> There is a line in the (Wil Stuckey's) star ratings plugin that looks
> like this:
>
>   stars.eq(averageIndex).addClass('on').children('a').css('width',
> percent + "%");
>
> I found that the eq() function was not returning 1 item, but rather
> all matching items from averageIndex to the end of the items.
>
> My first thought was that perhaps a bug was introduced when eq() was
> removed then readded. so I changed it to use a slice:
>
>   stars.slice(averageIndex, averageIndex +
> 1).addClass('on').children('a').css('width', percent + "%");
>
> To my dismay, slice() was also refusing to return a single item!
>
> I decided at this point to try implementing this functionality via a
> selector:
>
>   $('div.star:eq('+averageIndex
> +')').addClass('on').children('a').css('width', percent + "%");
>
> This worked and only returned the single item I cared about.
>
> It seems like something is very wrong for eq() and slice(x, x+1) to
> both return more than a single element?  How can this possibly occur?
>
> - Jim

Reply via email to