3 ms·
Question: When would you ever want the .attr("value")=="initial" in real code? How often is it that you want the original value encoded in the HTML as opposed
by pak 15y ago
Question: When would you ever want the .attr("value")=="initial" in real code? How often is it that you want the original value encoded in the HTML as opposed to the current value of the element as entered by the user?
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.
- timdown 15y agoThe difference between attributes and properties is not an inane detail. It's fundamental, and if you don't understand it then you can't work reliably with the DOM, either with or without jQuery. Bottom line: use prop().
- donalm 15y agoYou could use it to test if the value has been changed.