Can I, the developer of jQuery1.9 +, "refuse" to use the attr() method in my daily work?
As shown in many questions,
- .prop () vs .attr () (main)
- jQuery attr vs. prop, is there a list of details?
- jQuery attr vs prop?
- Migrating jQuery 1.8.3 to 1.9.0 - Replacing deprecated .attr ()
- ... etc....
There is a lot of confusion regarding the โuse of attr or the use of prop?โ, and from my (developer's) point of view, for all kinds of use of the attr() method, we can use prop instead:
- backward compatibility: the coding of new software does not need this;
- performance: John says "Accessing properties using the .attr () method will be slightly slower than accessing them directly through .prop ()";
- Change attribute value: everything can be changed using the
prop(name,newvalue) . - Remove attribute: everything can be removed using the
removeProp(name) method. - Check the values โโof the HTML attributes: the browser uses the DOM, all the HTML has been converted to the DOM, and if the DOM affected the
attr(name) method. About the "strong type" prop: better than "html string value" (for example, "checked" vs true). - Check if the attribute was defined in the "HTML source" (if this
attr method in your browser returns undefined, if it is not) ... Well, do we need this in some kind of software? In forms, the ".val () method is the recommended jQuery method to get or set form values" - Browser compatibility: both (not just attr) are consistent methods. (this is??).
So, at this time (2013), I see no good reason to use the attr method when developing new jQuery code ... But, well, this is, in other words, the question: Are there a good reason to use the attr method in my everyday tasks?
jquery deprecated attr prop
Peter Krauss Feb 25 '13 at 15:20 2013-02-25 15:20
source share