Side navigation
#9830 closed bug (duplicate)
Opened July 15, 2011 09:45AM UTC
Closed May 18, 2012 02:05AM UTC
Last modified May 18, 2012 02:05AM UTC
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
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')
Attachments (0)
Change History (22)
Changed July 15, 2011 01:13PM UTC by comment:1
component: | unfiled → attributes |
---|---|
keywords: | → needsreview |
milestone: | None → 1.next |
priority: | undecided → low |
status: | new → open |
Changed October 29, 2011 10:50PM UTC by comment:2
+1
Changed October 30, 2011 01:21AM UTC by comment:3
keywords: | needsreview → 1.8-discuss |
---|
Changed October 30, 2011 01:21AM UTC by comment:4
+1
Changed October 30, 2011 06:38PM UTC by comment:5
In the meantime - If you need attr("value")
to be true to the HTML attribute, you can delete $.attrHooks.value
- http://jsfiddle.net/KxVPH/
Changed October 30, 2011 06:39PM UTC by comment:6
+1
Changed November 05, 2011 06:25PM UTC by comment:9
This also affects Sizzle selections using the value attribute.
Changed November 09, 2011 02:29PM UTC by comment:10
#10731 is a duplicate of this ticket.
Changed November 18, 2011 03:21PM UTC by comment:11
#10823 is a duplicate of this ticket.
Changed December 13, 2011 01:45PM UTC by comment:12
description: | 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') \ }}} \ \ http://209.85.12.237/30095/43/0/f5198393/attrbug.htm \ \ → 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')\ }}}\ \ http://209.85.12.237/30095/43/0/f5198393/attrbug.htm\ \ |
---|
+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.
Changed December 13, 2011 04:03PM UTC by comment:13
+0, We need to make sure this doesn't break the web, so to speak.
Changed December 13, 2011 05:20PM UTC by comment:14
+0, this needs an actual deprecation first, there's no mention on http://api.jquery.com/attr/
Changed December 15, 2011 03:51PM UTC by comment:15
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.
Changed December 19, 2011 05:18PM UTC by comment:16
description: | 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')\ }}}\ \ http://209.85.12.237/30095/43/0/f5198393/attrbug.htm\ \ → 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') \ }}} \ \ http://209.85.12.237/30095/43/0/f5198393/attrbug.htm \ \ |
---|
+0, It seems obvious right? My concern is BC breakage
Changed January 02, 2012 04:00PM UTC by comment:17
-1, Needs deprecation first
Changed January 02, 2012 09:28PM UTC by comment:18
@dmethvin: it has already been deprecated. http://blog.jquery.com/2011/11/08/building-a-slimmer-jquery/
Changed February 15, 2012 03:26PM UTC by comment:19
#11345 is a duplicate of this ticket.
Changed March 03, 2012 08:58PM UTC by comment:20
milestone: | 1.next → 1.8 |
---|
Changed May 18, 2012 02:05AM UTC by comment:21
resolution: | → duplicate |
---|---|
status: | open → closed |
Changed May 18, 2012 02:05AM UTC by comment:22
Duplicate of #11735.
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