Although I'm honestly a bit confused on their explanation of .prop and .attr now... Maybe I should just re-read it slower, or give myself a little more time to wake up. Unless someone would care to explain it in simpler terms for me. ;)
Although I'm honestly a bit confused on their explanation of .prop and .attr now... Maybe I should just re-read it slower, or give myself a little more time to wake up. Unless someone would care to explain it in simpler terms for me. ;)
Additionally there is the concept of DOM object properties - these are properties that exist solely on the JavaScript implementation of the DOM node. For example .selectedIndex is a property that exists on select elements but isn't actually an attribute.
Previously jQuery conflated properties and attributes (sometimes using one, sometimes using another). Unfortunately, while this creates a result that is perhaps slightly more user friendly, it also creates lots of weird edge cases that are hard to define (such as the cases relating to value, outlined in the blog post). For this reason we've split apart the functionality into two realms: .attr()/.removeAttr() and .prop()/.removeProp().
How does this affect you and your applications? It probably (hopefully) won't. Continuing to use .attr()/.removeAttr() will probably be just fine. Using other jQuery helpers, like .val(), will help to cover over the last remaining bits of weirdness that exist.
In short: Nothing much of serious consequence will likely change, but we're going to actively watch the response from this release and make sure we act appropriately, and swiftly, should major problems come up.
Your blog post calls them "breaking changes" for a reason though. Code that does `if ($elem.attr('checked'))` needs to be rewritten to use .prop when upgrading. Saying "It probably (hopefully) won't [affect your applications]" is slightly contradictory.
I'll go through my code a bit to see if I need to make any changes, but it doesn't seem that way now that it's all more clarified for me.. Besides a couple cases where I check the state of checkboxes. Thanks again for your help, and for jQuery in general. It's made my life/job easier in a completely indescribable way. (I used to be afraid of Javascript.)
Saying that it probably won't affect existing applications is just misleading. 1.6 fundamentally changes the behaviour of attr(), which is a very complicated and commonly used method. Furthermore, there's really no point in this if you're not going to encourage people to move to prop() rather than attr().
The messages coming from jQuery about this change seem very vague to me. If you're going to spring this kind of change on your users then they need to understand what it is that you've changed and why it's a good thing (I think it is, by the way), which one documented example and a hand-wavy assurance that it might probably be mostly OK doesn't do.
If you have: <input id="test" type="text" value="initial" />
On load, the page should show for $("#test") .prop("value") = "initial", .attr("value") = "initial"
Then, if you type in "current" into the 'test' input box, the page should show: .prop("value") = "current", .attr("value") = "initial" without any other events taking place that would update the value.
This is part of why I think .prop vs .attr is a regression. It makes me think twice before I use either--even if this is closer to how the DOM actually behaves, the point of jQuery used to be that it could hide those inane details from me.
Bottom line: use prop().