Skip to main content

Bug Tracker

Side navigation

#9022 closed bug (worksforme)

Opened April 29, 2011 11:33PM UTC

Closed April 30, 2011 02:49PM UTC

Last modified April 30, 2011 03:04PM UTC

Negative eq() in IE does not return null

Reported by: Motty Owned by: Motty
Priority: low Milestone: 1.next
Component: traversing Version: 1.5.2
Keywords: Cc:
Blocked by: Blocking:
Description

I found a problem in older IE browsers (pre-IE9) where using a ":eq(n)" selector, where "n" is negative, returns ":eq(0)". This occurs in all jQuery versions except 1.2.6.

Here is a demo of the problem

Attachments (0)
Change History (5)

Changed April 29, 2011 11:51PM UTC by Motty comment:1

_comment0: Oh, I also found that using ".eq(-1)" also messes up, so far, in IE, Firefox and Chrome. I haven't tested the other browsers. \ \ [http://jsfiddle.net/Mottie/TuRNp/2/ Updated demo]1304175946155697

Oh, I also found that using ".eq(-1)" also messes up, so far, in IE, Firefox and Chrome. I haven't tested the other browsers.

Updated demo

*** IGNORE THIS, THIS WORKS AS INTENDED! ***

Changed April 29, 2011 11:59PM UTC by rwaldron comment:2

_comment0: A simpler reduction: http://jsfiddle.net/rwaldron/TuRNp/3/ \ \ Can someone with appropriate browsers test this?1304124848006461
component: unfiledtraversing
owner: → Motty
status: newpending

A simpler reduction: http://jsfiddle.net/rwaldron/TuRNp/3/

Can someone with appropriate browsers test this?

Also, just in case it wasn't clear, if you have one element, 0 is the same as -1

Changed April 30, 2011 01:16AM UTC by Motty comment:3

_comment0: In the simpler reduction demo, this also returns true: \ \ {{{ \ $test.eq(null).length === 1 // true \ }}}1304175989682671
status: pendingnew

In the simpler reduction demo, this also returns true:

$test.eq(null).length === 1 // true
  • IGNORE THIS, IT WORKS AS INTENDED! *

Changed April 30, 2011 02:49PM UTC by rwaldron comment:4

priority: undecidedlow
resolution: → worksforme
status: newclosed

Thanks for the clarification, much appreciated.

According to the api docs, eq() accepts only integers: http://api.jquery.com/eq

Changed April 30, 2011 03:04PM UTC by Motty comment:5

_comment0: Hiya.. sorry, I need to clarify. I shouldn't have added in the ".eq()" examples as I forgot about how it treats negative integers. But ":eq()" acts completely different! \ \ If I use ":eq(n)" in modern browsers, negative integers return null \ \ {{{ \ $test.filter(':eq(-1)') // returns null \ }}} \ \ In IE8 and older, it returns the element ':eq(0)'. \ \ {{{ \ $test.filter(':eq(-1)') // returns $test.filter(':eq(0)') \ }}} \ \ Here is a [http://jsfiddle.net/Mottie/TuRNp/4/ test example] to clarify... run it in IE1304176612034288
_comment1: Hiya.. sorry, I need to clarify. I shouldn't have added in the ".eq()" examples as I forgot about how it treats negative integers. But ":eq()" acts completely different! \ \ If I use ":eq(n)" in modern browsers, negative integers return null \ \ {{{ \ $test.filter(':eq(-1)') // returns null \ }}} \ \ In IE8 and older, it returns the element ':eq(0)'. \ \ {{{ \ $test.filter(':eq(-1)') // returns $test.filter(':eq(0)') \ }}} \ \ Here is a [http://jsfiddle.net/Mottie/TuRNp/5/ test example] to clarify... run it in IE1304176695195183

Hiya.. sorry, I need to clarify. I shouldn't have added in the ".eq()" examples as I forgot about how it treats negative integers. But :eq() acts completely different and does not work with negative integers!

If I use ":eq(n)" in modern browsers, negative integers return null

$test.filter(':eq(-1)') // returns null

In IE8 and older, it returns the element ':eq(0)'.

$test.filter(':eq(-1)') // returns $test.filter(':eq(0)')

Here is a test example to clarify... run it in IE