Created
August 9, 2011 20:57
-
-
Save kevinthompson/1135171 to your computer and use it in GitHub Desktop.
Clear Default Text Input Value on Focus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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