Skip to content

Instantly share code, notes, and snippets.

@mattborn
Created June 24, 2010 20:54
Show Gist options
  • Save mattborn/451961 to your computer and use it in GitHub Desktop.
Save mattborn/451961 to your computer and use it in GitHub Desktop.
/* Clear 'dem Fields by Matthew Born */
$('input[type=text]').focus(function(){
if(!$(this).attr('placeholder')){
if(!$(this).val()){
$(this).attr('placeholder', ' ');
$(this).val('').addClass('active');
} else {
$(this).attr('placeholder', $(this).val());
$(this).val('').addClass('active');
}
} else if($(this).val() === $(this).attr('placeholder')){
$(this).val('').addClass('active');
}
}).blur(function(){
if(!$(this).val()){
if($(this).attr('placeholder') === ' '){
$(this).val('');
} else {
$(this).val($(this).attr('placeholder'));
} $(this).removeAttr('placeholder').removeClass('active')
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment