After a user presses a key in the div the html is set to ” “. However, after the user has left the div I would like to set the html back to it’s original value. How can I do that?
I have the following code so far:
$(document).one('keypress',"#id",function() {
$(this).html("");
}).focusout(function(){
//do something
});
Cache it in the element itself using
.data():I prefer this approach because by storing the data on
this, it works with any selector, including those that match multiple DOM elements. You just need to be sure thedata()variable ('html'here) isn’t being used by any other code on the page.