(Note: While it may be tempting to say this is a duplicate of .prop() vs .attr(), I do not believe it is. That post does a fantastic job explaining the difference between .prop()
and .attr()
but does not state definitively when one is preferable over the other, which is what this question aims to do.)
Despite having read a number of questions/answers on StackOverflow regarding the differences between .prop()
and .attr()
, I still see a lot of confusion on this issue.
I feel it would be useful to have a definitive reference on StackOverflow delineating when one method is preferable to the other, so that we can eliminate the guesswork and attempts at trying to figure out whether something is an attribute or a property.
Thus, I ask, for which attributes/properties is it preferable to use .prop()
and for which .attr()
?