Skip to content

Instantly share code, notes, and snippets.

@elfeffe
Created April 25, 2014 16:02
Show Gist options
  • Select an option

  • Save elfeffe/11294549 to your computer and use it in GitHub Desktop.

Select an option

Save elfeffe/11294549 to your computer and use it in GitHub Desktop.
Clean inputs on focus, and refill on blur
<script type="text/javascript">
jQuery.fn.doCleanInputs = function () {
jQuery(this).each(function() {
var default_value = this.value;
jQuery(this).focus(function(){
if(this.value == default_value) {this.value = '';}
});
jQuery(this).blur(function(){
if(this.value == '') {this.value = default_value;}
});
});
};
</script>
Usage:
jQuery('.cleaninputs').doCleanInputs();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment