Skip to main content

Bug Tracker

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')

http://209.85.12.237/30095/43/0/f5198393/attrbug.htm

Attachments (0)
Change History (22)

Changed July 15, 2011 01:13PM UTC by timmywil comment:1

component: unfiledattributes
keywords: → needsreview
milestone: None1.next
priority: undecidedlow
status: newopen

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

Changed October 29, 2011 10:50PM UTC by addyosmani comment:2

+1

Changed October 30, 2011 01:21AM UTC by timmywil comment:3

keywords: needsreview1.8-discuss

Changed October 30, 2011 01:21AM UTC by timmywil comment:4

+1

Changed October 30, 2011 06:38PM UTC by gnarf 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 gnarf comment:6

+1

Changed November 05, 2011 06:25PM UTC by timmywil comment:7

#10383 is a duplicate of this ticket.

Changed November 05, 2011 06:25PM UTC by timmywil comment:8

#10096 is a duplicate of this ticket.

Changed November 05, 2011 06:25PM UTC by timmywil comment:9

This also affects Sizzle selections using the value attribute.

Changed November 09, 2011 02:29PM UTC by timmywil comment:10

#10731 is a duplicate of this ticket.

Changed November 18, 2011 03:21PM UTC by timmywil comment:11

#10823 is a duplicate of this ticket.

Changed December 13, 2011 01:45PM UTC by mikesherov 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 jaubourg 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 jzaefferer 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 markel 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 rwaldron 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 dmethvin comment:17

-1, Needs deprecation first

Changed January 02, 2012 09:28PM UTC by timmywil 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 timmywil comment:19

#11345 is a duplicate of this ticket.

Changed March 03, 2012 08:58PM UTC by dmethvin comment:20

milestone: 1.next1.8

Changed May 18, 2012 02:05AM UTC by dmethvin comment:21

resolution: → duplicate
status: openclosed

Changed May 18, 2012 02:05AM UTC by dmethvin comment:22

Duplicate of #11735.