Organizational Research By

Surprising Reserch Topic

Question:Why jQuery 1.9+ attr() method not deprecated?



asked Sep 13, 2013 in jquery by anonymous
edited Sep 12, 2013
0 votes
25 views



Related Hot Questions

4 Answers

0 votes

It's not deprecated because it's useful when you use it for what it's made for. .attr() retrieves attributes, while .prop() retrieves properties. The two are different things (though the DOM often has a property to correspond to an attribute). If you have a

, where whatever is not an attribute the browser recognizes, you'd use .attr() to get the attribute's value. .prop() wouldn't even be able to see it in most browsers.

answered Sep 13, 2013 by anonymous
edited Sep 12, 2013
0 votes
Can I, a jQuery1.9+ software developer, "deprecate" the use of the attr() method in my day-by-day work?

there are a lot of confusion about "use attr or use prop?", and, by my (developer's) view point, for all uses of attr() method, we can use prop instead:

    backward-compatibility: coding new software not need this;
    performance: John says "Accessing properties through the .attr() method will be slightly slower than accessing them directly through .prop()";
    Change attribute value: all can be changed by the prop(name,newvalue) method.
    Remove attribute: all can be removed by the removeProp(name) method.
    Check HTML attribute values: browser use DOM, all HTML was converted to DOM, and, if DOM affected the attr(name) method also affected. About "strong type" of prop: it is better than "html string value" (ex. "checked" vs true).
    Check if an attribute was defined in the "HTML original code" (supposing that method attr in your browser returns undefined if it is not)... Well, we need this in some piece of software? At forms, ".val() method is the recommended jQuery way to get or set the values of form"
    Cross-browser consistency: both (not only attr) are consistent methods. (it is??).

So, at this time (2013), I not see a good reason to use attr method when developing new jQuery code... But, well, this is, in other words, the question: There are a good reason to use attr method in my day-by-day tasks?
answered Sep 13, 2013 by anonymous
edited Sep 12, 2013
0 votes

It's not deprecated because it's useful when you use it for what it's made for. .attr() retrieves attributes, while .prop() retrieves properties. The two are different things (though the DOM often has a property to correspond to an attribute). If you have a

, where whatever is not an attribute the browser recognizes, you'd use .attr() to get the attribute's value. .prop() wouldn't even be able to see it in most browsers.

answered Sep 13, 2013 by anonymous
edited Sep 12, 2013
0 votes
Can I, a jQuery1.9+ software developer, "deprecate" the use of the attr() method in my day-by-day work?

there are a lot of confusion about "use attr or use prop?", and, by my (developer's) view point, for all uses of attr() method, we can use prop instead:

    backward-compatibility: coding new software not need this;
    performance: John says "Accessing properties through the .attr() method will be slightly slower than accessing them directly through .prop()";
    Change attribute value: all can be changed by the prop(name,newvalue) method.
    Remove attribute: all can be removed by the removeProp(name) method.
    Check HTML attribute values: browser use DOM, all HTML was converted to DOM, and, if DOM affected the attr(name) method also affected. About "strong type" of prop: it is better than "html string value" (ex. "checked" vs true).
    Check if an attribute was defined in the "HTML original code" (supposing that method attr in your browser returns undefined if it is not)... Well, we need this in some piece of software? At forms, ".val() method is the recommended jQuery way to get or set the values of form"
    Cross-browser consistency: both (not only attr) are consistent methods. (it is??).

So, at this time (2013), I not see a good reason to use attr method when developing new jQuery code... But, well, this is, in other words, the question: There are a good reason to use attr method in my day-by-day tasks?
answered Sep 13, 2013 by anonymous
edited Sep 12, 2013

...