Bug Tracker

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#8373 closed bug (duplicate)

input:text[val=xy]:first selector and actual input value

Reported by: romuald Owned by:
Priority: low Milestone: 1.next
Component: selector Version: 1.5
Keywords: Cc:
Blocked by: Blocking:

Description

Hi

Example currently at: http://jsfiddle.net/dsjy6/3/

With the following selector:

#someid input:text[value='']:first

which should return the first empty input inside the #someid element (otherwise, the problem is on my side :)

jQuery will currently only return the first input that was empty when the page was loaded.

In the example, clicking multiple times on the link will only update the 3rd input each time.

The second code example works fine (modifying the first element of the list, without :first)

Moreover, I found out that removing #someid will work correctly (but in my case, this is not what I want)

Tested with 1.5 and 1.4.4

Version 1.3.2 works as intended

Change History (4)

comment:1 Changed 8 years ago by dmethvin

Component: unfiledselector
Priority: undecidedlow

The user's input changes the value property of the element but not the value attribute.

If the element has value="abc" and you type the characters def to replace them, the attribute is value="abc" but the .value="def".

Sizzle (the selector engine for jQuery) first tries to use the standard querySelectorAll browser method. The standard says that the selector should only consider the *attribute* value and not the dynamic property value. So in those cases you would be matching against "abc" and not "def".

However, all three of those examples use non-standard selector extensions (:text and :first in particular) so they go through Sizzle's Javascript-based selector engine instead. That engine does look at the *property* so it will see the dynamic change the user made. Browsers without querySelectorAll (IE6/7) would also have this behavior on standard selectors.

So with that in mind it's not a good idea to expect selectors to take into account the dynamic values that a user may have just typed.

All that said, I am not sure why the first example behaves the way it does. Seems like it should work the way the last example does. #main input:text[value=''] selects 5 elements but #main input:text[value='']:first selects nothing in IE! So I do think something is broken here.

comment:2 Changed 8 years ago by Rick Waldron

Status: newopen

comment:3 Changed 8 years ago by john

Resolution: duplicate
Status: openclosed

comment:4 Changed 8 years ago by john

Duplicate of #9810.

Note: See TracTickets for help on using tickets.