Bug Tracker

Opened 12 years ago

Closed 11 years ago

Last modified 11 years ago

#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 Rick Waldron)

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

Change History (22)

comment:1 Changed 12 years ago by timmywil

Component: unfiledattributes
Keywords: needsreview added
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

comment:2 Changed 11 years ago by addyosmani

+1

comment:3 Changed 11 years ago by timmywil

Keywords: 1.8-discuss added; needsreview removed

comment:4 Changed 11 years ago by timmywil

+1

comment:5 Changed 11 years 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:6 Changed 11 years ago by gnarf

+1

comment:7 Changed 11 years ago by timmywil

#10383 is a duplicate of this ticket.

comment:8 Changed 11 years ago by timmywil

#10096 is a duplicate of this ticket.

comment:9 Changed 11 years ago by timmywil

This also affects Sizzle selections using the value attribute.

comment:10 Changed 11 years ago by timmywil

#10731 is a duplicate of this ticket.

comment:11 Changed 11 years ago by timmywil

#10823 is a duplicate of this ticket.

comment:12 Changed 11 years 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 11 years ago by jaubourg

+0, We need to make sure this doesn't break the web, so to speak.

comment:14 Changed 11 years ago by jzaefferer

+0, this needs an actual deprecation first, there's no mention on http://api.jquery.com/attr/

comment:15 Changed 11 years 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 11 years ago by Rick Waldron

Description: modified (diff)

+0, It seems obvious right? My concern is BC breakage

comment:17 Changed 11 years ago by dmethvin

-1, Needs deprecation first

comment:18 Changed 11 years ago by timmywil

@dmethvin: it has already been deprecated. http://blog.jquery.com/2011/11/08/building-a-slimmer-jquery/

comment:19 Changed 11 years ago by timmywil

#11345 is a duplicate of this ticket.

comment:20 Changed 11 years ago by dmethvin

Milestone: 1.next1.8

comment:21 Changed 11 years ago by dmethvin

Resolution: duplicate
Status: openclosed

comment:22 Changed 11 years ago by dmethvin

Duplicate of #11735.

Note: See TracTickets for help on using tickets.