Skip to content

Instantly share code, notes, and snippets.

@kevinthompson
Created August 9, 2011 20:57
Show Gist options
  • Save kevinthompson/1135171 to your computer and use it in GitHub Desktop.
Save kevinthompson/1135171 to your computer and use it in GitHub Desktop.
Clear Default Text Input Value on Focus
// Clear Default Text Input Value on Focus
$('input[type="text"]').each(function(){
var def = $(this).attr('placeholder') != '' && $(this).attr('placeholder') != undefined ? $(this).attr('placeholder') : $(this).attr('value');
$(this).val(def).attr('placeholder','');
$(this).focus(function(){
if($(this).val() == def){
$(this).removeClass('placeholder').val('');
}
}).blur(function(){
if($(this).val() == ''){
$(this).addClass('placeholder').val(def);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment