Bug Tracker

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#14064 closed bug (notabug)

:eq return different object in 1.10.1

Reported by: htpu Owned by: htpu
Priority: undecided Milestone: None
Component: unfiled Version: 1.10.1
Keywords: Cc:
Blocked by: Blocking:

Description

For the following html dom:

<div id="container">
    <div id="a"><div id="b"></div></div>
    <div id="c"><div id="d"></div></div>
</div>

the following JS code:

$("#container > * :eq(1)")

returns div.#c in jquery 1.9.x but returns div.#d in jquery 1.10.1

Change History (5)

comment:1 Changed 6 years ago by dmethvin

Owner: set to htpu
Status: newpending

So which result do you like best? I have a preference for what 1.10 returns.

comment:2 in reply to:  1 ; Changed 6 years ago by htp2008@…

Replying to dmethvin:

So which result do you like best? I have a preference for what 1.10 returns.

After carefully testing, I found it's a bug in 1.10.1

Two selectors returns different result '#container > *:eq(1)' returns: c '#container > * :eq(1)' returns: d Note the only difference is that in the 2nd selector there is a space between "*" and ":eq" But the two selectors return the same result, c, in 1.9.1, which is the correct behavior

Please test it at http://jsfiddle.net/nVUpc/2/

comment:3 in reply to:  2 ; Changed 6 years ago by gibson042

Resolution: notabug
Status: pendingclosed

Replying to htp2008@…:

Two selectors returns different result '#container > *:eq(1)' returns: c '#container > * :eq(1)' returns: d Note the only difference is that in the 2nd selector there is a space between "*" and ":eq" But the two selectors return the same result, c, in 1.9.1, which is the correct behavior

The space between "*" and ":eq(1)" is not meaningless; it is a descendant combinator:

  • "#container > *:eq(1)" matches the second element child of #container.
  • "#container > * :eq(1)" matches the second element in the list of all descendants of element children of #container (equivalent to "#container > * *:eq(1)").

1.10.1 implements the correct behavior in http://jsfiddle.net/nVUpc/2/.

comment:4 in reply to:  3 Changed 6 years ago by htp2008@…

Replying to gibson042:

Replying to htp2008@…:

Two selectors returns different result '#container > *:eq(1)' returns: c '#container > * :eq(1)' returns: d Note the only difference is that in the 2nd selector there is a space between "*" and ":eq" But the two selectors return the same result, c, in 1.9.1, which is the correct behavior

The space between "*" and ":eq(1)" is not meaningless; it is a descendant combinator:

  • "#container > *:eq(1)" matches the second element child of #container.
  • "#container > * :eq(1)" matches the second element in the list of all descendants of element children of #container (equivalent to "#container > * *:eq(1)").

1.10.1 implements the correct behavior in http://jsfiddle.net/nVUpc/2/.

According to the document

A descendant combinator is whitespace that separates two sequences of simple selectors

Which are simple selectors? And which are not? Are "*" and ":eq" both simple selectors?
I think the prvious behavior is more reasonable since most developers would not care the space before ":eq" or ":last" or ":XXX"

comment:5 Changed 6 years ago by gibson042

http://www.w3.org/TR/css3-selectors/#descendant-combinators

Simple selectors are basically the "atoms" of selector expressions.

Edit: http://www.w3.org/TR/css3-selectors/#simple-selectors, rather

Last edited 6 years ago by gibson042 (previous) (diff)
Note: See TracTickets for help on using tickets.