Ticket #9830 (closed bug: duplicate)
Getting the value of the "value" attribute using .attr("value") is the same as using .val()
| Reported by: | Quozzo | Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | 1.8 |
| Component: | attributes | Version: | 1.6.2 |
| Keywords: | 1.8-discuss | Cc: | |
| Blocking: | Blocked by: |
Description (last modified by rwaldron) (diff)
Using .attr("value") returns the same as using .val() although the "value" attribute remains unchanged in the DOM, as seen by Dragonfly on Opera. New text entered in an input should be returned with .val() but not .attr("value") which should return the value of the "value" attribute, that getAttribute() does.
$('#foo').val() == $('#foo').attr('value')
Change History
comment:1 Changed 22 months ago by timmywil
- Keywords needsreview added
- Priority changed from undecided to low
- Status changed from new to open
- Component changed from unfiled to attributes
- Milestone changed from None to 1.next
comment:5 Changed 19 months ago by gnarf
In the meantime - If you need attr("value") to be true to the HTML attribute, you can delete $.attrHooks.value- http://jsfiddle.net/KxVPH/
comment:9 Changed 19 months ago by timmywil
This also affects Sizzle selections using the value attribute.
comment:10 Changed 19 months ago by timmywil
#10731 is a duplicate of this ticket.
comment:11 Changed 18 months ago by timmywil
#10823 is a duplicate of this ticket.
comment:12 Changed 17 months ago by mikesherov
- Description modified (diff)
+1, Tentative +1, although this might get a similar reaction to the .prop stuff introduced in 1.6. However, I think that risk is low, and we can't always be held back by past decisions that are not a good idea in hindsight. Of course, shout from the rooftops about this when the change is made.
comment:13 Changed 17 months ago by jaubourg
+0, We need to make sure this doesn't break the web, so to speak.
comment:14 Changed 17 months ago by jzaefferer
+0, this needs an actual deprecation first, there's no mention on http://api.jquery.com/attr/
comment:15 Changed 17 months ago by markel
Maybe its not my place to say this. But please, please dont do this --
1) Its breaking change, a lot of code will not work with this -- http://www.google.com/codesearch#search/&q=%5C.attr%5C(%22value%22%5C)%20lang:%5Ejavascript$&type=cs Its not what you promise us -- http://ejohn.org/blog/jquery-16-and-attr/
2) It will be inconsistent with another getters of properties, for example like "checked" and "selected". When user can change input state, not from code, but just clicking on it. Attr will still return a property whereas in html they will stay the same, but for value it will be diffrent?
Distinguish properties and attributes is tempting and logical, but you already make this decision way back. On my opinion -- you have to stick with it.
comment:16 Changed 17 months ago by rwaldron
- Description modified (diff)
+0, It seems obvious right? My concern is BC breakage
comment:17 Changed 17 months ago by dmethvin
-1, Needs deprecation first
comment:18 Changed 17 months ago by timmywil
@dmethvin: it has already been deprecated. http://blog.jquery.com/2011/11/08/building-a-slimmer-jquery/
comment:19 Changed 15 months ago by timmywil
#11345 is a duplicate of this ticket.
comment:21 Changed 12 months ago by dmethvin
- Status changed from open to closed
- Resolution set to duplicate
comment:22 Changed 12 months ago by dmethvin
Duplicate of #11735.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

I agree completely. Unfortunately, attr retrieved the value property in the past so we've kept that for backwards compatibility reasons by adding an attrHook for value. I'd like to deprecate that since we have both .val and .prop now. On that note, I'm adding needsreview.
+1 to deprecate in 1.7, remove in 1.8