Side navigation
#8373 closed bug (duplicate)
Opened February 24, 2011 05:35PM UTC
Closed July 12, 2011 05:07PM UTC
Last modified July 12, 2011 05:07PM UTC
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
Attachments (0)
Change History (4)
Changed February 24, 2011 11:19PM UTC by comment:1
component: | unfiled → selector |
---|---|
priority: | undecided → low |
Changed March 07, 2011 12:27AM UTC by comment:2
status: | new → open |
---|
Further reduced: http://jsfiddle.net/rwaldron/amvV3/
Changed July 12, 2011 05:07PM UTC by comment:3
resolution: | → duplicate |
---|---|
status: | open → closed |
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 charactersdef
to replace them, the attribute isvalue="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.