Ticket #12241 (closed bug: fixed)
Passing a negative index for :eq throws a syntax error.
| Reported by: | r.osenkonstantinov@… | Owned by: | timmywil |
|---|---|---|---|
| Priority: | low | Milestone: | 1.8.1 |
| Component: | selector | Version: | 1.8.0 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
If negative index is set for :eq a syntax error is thrown. Here is a basic selector: $("div").children(":eq(-1)") and a jsbin sample http://jsbin.com/ovurif/1/edit.
The documentation states that it is not supported but an empty set will be returned. Which unfortunately is not true with the 1.8:
"Unlike the .eq(index) method, the :eq(index) selector does not accept a negative value for index. For example, while $('li').eq(-1) selects the last li element, $('li:eq(-1)') selects nothing."
Change History
comment:1 Changed 10 months ago by timmywil
- Owner set to timmywil
- Priority changed from undecided to low
- Status changed from new to assigned
- Component changed from unfiled to selector
- Milestone changed from None to 1.8.1
comment:2 Changed 10 months ago by dmethvin
Well, working as documented, which is to say they return nothing.
comment:3 Changed 10 months ago by timmywil
Actually, I was thinking it would be easy to make it work the same way as the method.
comment:4 Changed 9 months ago by Timmy Willison
- Status changed from assigned to closed
- Resolution set to fixed
Sizzle: support negative numbers in :eq. Fixes #12241.
Changeset: fbdf8bed4fa34b6c922a287060ffaa01a55245a9
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

I don't have a problem with negative values working. We can fix that in the next patch release.