Skip to content

Instantly share code, notes, and snippets.

@HoundstoothSTL
Created November 15, 2012 20:01
Show Gist options
  • Save HoundstoothSTL/4080880 to your computer and use it in GitHub Desktop.
Save HoundstoothSTL/4080880 to your computer and use it in GitHub Desktop.
jQuery Input Clearing
// Input Clearing
$.fn.cleardefault = function() {
return this.focus(function() {
if( this.value == this.defaultValue ) {
this.value = '';
}
}).blur(function() {
if( !this.value.length ) {
this.value = this.defaultValue;
}
});
};
// Just add the .clearit class to a parent tag or input directly
$('.clearit, .clearit input, .clearit textarea').cleardefault();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment