#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: | |
Blocked by: | Blocking: |
Description (last modified by )
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 (22)
comment:1 Changed 12 years ago by
Component: | unfiled → attributes |
---|---|
Keywords: | needsreview added |
Milestone: | None → 1.next |
Priority: | undecided → low |
Status: | new → open |
comment:3 Changed 11 years ago by
Keywords: | 1.8-discuss added; needsreview removed |
---|
comment:5 Changed 11 years ago by
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:12 Changed 11 years ago by
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 11 years ago by
+0, We need to make sure this doesn't break the web, so to speak.
comment:14 Changed 11 years ago by
+0, this needs an actual deprecation first, there's no mention on http://api.jquery.com/attr/
comment:15 Changed 11 years ago by
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 11 years ago by
Description: | modified (diff) |
---|
+0, It seems obvious right? My concern is BC breakage
comment:18 Changed 11 years ago by
@dmethvin: it has already been deprecated. http://blog.jquery.com/2011/11/08/building-a-slimmer-jquery/
comment:20 Changed 11 years ago by
Milestone: | 1.next → 1.8 |
---|
comment:21 Changed 11 years ago by
Resolution: | → duplicate |
---|---|
Status: | open → closed |
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