Skip to content

Instantly share code, notes, and snippets.

@andreruffert
Created February 18, 2011 11:12
Show Gist options
  • Save andreruffert/833549 to your computer and use it in GitHub Desktop.
Save andreruffert/833549 to your computer and use it in GitHub Desktop.
Clear input fields on focus with text replacement if nothing is entered
$('input').each(function(){
$(this)
.data('default', $(this).val())
.focus(function(){
if ($(this).val() == $(this).data('default') || ''){
$(this).val('');
}
})
.blur(function(){
if ($(this).val() == '') {
$(this).val($(this).data('default'));
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment