For example we have html input with value=”wally”:
<input type="text" value="wally" />
How to get this old “wally” value (using jQuery) after user change it?
I tried to get it with .attr(), .prop(), .val() but all of them return the new value, which user entered.
You may test the code on jsfiddle. Try to change input value and click “get” blue button.
P.S. jQuery 1.7.2 included into the jsfiddle.
Use
defaultValueof the underlying DOM element:Updated fiddle
And of course, if you’re using jQuery 1.6 or higher, you can use
prop('defaultValue')for that (and in earlier versions,attr('defaultValue')probably works):Updated fiddle