Ticket #3520 (closed bug: duplicate)
.eq(n) acts funny
| Reported by: | sorpigal | Owned by: | |
|---|---|---|---|
| Priority: | minor | Milestone: | 1.3 |
| Component: | core | Version: | 1.2.6 |
| Keywords: | Cc: | sorpigal, flesler | |
| Blocking: | Blocked by: |
Description
When passing .eq() a variable containing an integer parsed out of a string the results are strange. In my case I was passing 0, 1 or 2 based on the values found in a string. When passing 0 and 2 I got expected results, when passing 1 I found that .eq(n).length == 2, which is very wrong.
I do not have a simple test case for this, but the fix is:
eq: function( i ) {
return this.slice( +i, +i + 1 );
},
The unary + forces i to be a number. I think there is no possible harm to this and it will save many people frustration. Technically, of course, it is user error.
Change History
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

This should be fixed in trunk.
Can you try with this file ? http://code.jquery.com/jquery-nightly.js
Do post back even if it works so that I can close this.