Bug Tracker

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#9463 closed bug (wontfix)

attr() yields different results in 1.5.2 and 1.6.1

Reported by: begraves@… Owned by:
Priority: low Milestone: 1.next
Component: attributes Version: 1.6.1
Keywords: Cc:
Blocked by: Blocking:

Description

...which breaks the statement "when updating from 1.5.2 to 1.6.1, you should not have to change any attribute code" in the blog.

Examples:

$("<textarea>").attr("type") is undefined in 1.6.1, while "textarea" is returned in 1.5.2 (which is returned by $("<textarea>").prop("type") in 1.6.1).

The same holds for $("<select>").attr("type") and $("<input>").attr("type") (and maybe even more) analogously, see http://jsfiddle.net/HHgw5/ and http://jsfiddle.net/TZxmy/ .

Change History (12)

comment:1 Changed 8 years ago by timmywil

Component: unfiledattributes
Priority: undecidedlow
Resolution: wontfix
Status: newclosed

Thanks for taking the time to contribute to the jQuery project! This is intended behavior for the type attribute as it allows you differentiate between the actual attribute and the property. Nevertheless, the most common use cases consist of setting the type attribute on a disconnected node and possibly retrieving it later. For instance, http://jsfiddle.net/timmywil/At4Hh/

comment:2 in reply to:  1 Changed 8 years ago by begraves@…

This is intended behavior for the type attribute...

Hi timmywil, thanks for your quick response. I understand your point of view, nevertheless the statement "when updating from 1.5.2 to 1.6.1, you should not have to change any attribute code" is plain wrong and should be corrected in the blog.
1.6.1 is not backwards compatible with 1.5.2, at least regarding to the attr-function.

comment:3 Changed 8 years ago by yeurch

I have to agree completely with begraves, the statement "when updating from 1.5.2 to 1.6.1, you should not have to change any attribute code" is incorrect. Please consider reopening this issue.

comment:4 Changed 8 years ago by timmywil

I understand the confusion, but technically the statement is still valid. This is not attribute code we're talking about in this ticket.

comment:5 in reply to:  4 Changed 8 years ago by yeurch

Replying to timmywil:

I understand the confusion, but technically the statement is still valid. This is not attribute code we're talking about in this ticket.

I certainly don't want this comment thread to go round in circles, so I will finish by saying that regardless of whether this is technically attribute code or not, I believe that it is a breaking change introduced between 1.5.2 and 1.6.1 and should either be fixed or documented as such.

comment:6 in reply to:  4 Changed 8 years ago by begraves@…

Replying to timmywil:

I understand the confusion, but technically the statement is still valid.

Ok, I give a longer citation from http://blog.jquery.it/2011/05/12/jquery-1-6-1-released/

When updating from 1.5.2 to 1.6.1, you should not have to change any attribute code. [...] However, as previously stated, jQuery 1.6.1 will allow you to use .attr() just as it was used before in all situations.

I think you have to agree that this statement is not correct. ;-)

comment:7 Changed 8 years ago by keith@…

Another change that's not backward-compatible is that .attr('id') on something that has no id used to return "", but in jQuery 1.6+ it now returns undefined. Unfortunately some code (specifically the Uniform plugin) tests for the existence of id by checking $el.attr != "" (which now is broken). It might be worth a warning in the docs.

comment:8 Changed 8 years ago by Rick Waldron

I suggest getting in touch with the author of Uniform and let them know that their plugin needs to be updated

comment:9 Changed 8 years ago by anonymous

It would be more than nice either to publish a complete list of backward incompatibilities for 1.6.1 or (better) to fix these incompatibilities in 1.6.2.

comment:10 Changed 8 years ago by Rick Waldron

The latter would just bring us back to the old "attr" - that timmywil worked _very_ hard to rewrite... so... non-starter. The former exists here: http://blog.jquery.com/2011/05/12/jquery-1-6-1-released/

comment:11 in reply to:  10 Changed 8 years ago by begraves@…

Replying to rwaldron:

The latter would just bring us back to the old "attr" - that timmywil worked _very_ hard to rewrite... so... non-starter. The former exists here: http://blog.jquery.com/2011/05/12/jquery-1-6-1-released/

...containing the incorrect statement

... jQuery 1.6.1 will allow you to use .attr() just as it was used before in all situations.

as stated above. John Resigs blog entry suggests that 1.6.1 (in contrast to 1.6) is backwards compatible with 1.5.2 which it is not. IMO this should be corrected or better/clearly documented.

But as yeurch said I don't want this to go round in circles too, so this was my last comment in this thread.

comment:12 Changed 8 years ago by Rick Waldron

In an effort to better explain the changes to attr() and the new prop() functionality, @dmethvin and I put these jsfiddle's together:

http://jsfiddle.net/rwaldron/BNcty/

http://jsfiddle.net/BNcty/4/

Hope this adds some clarity

Note: See TracTickets for help on using tickets.