Skip to content

Instantly share code, notes, and snippets.

@senko
Created February 16, 2012 13:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save senko/1844846 to your computer and use it in GitHub Desktop.
Save senko/1844846 to your computer and use it in GitHub Desktop.
HTML input field placeholder handling
/* Hide/show placeholder text in an input field while it's empty
* To use, add data-placheholder="placeholder text" to your fields
* Eg: <input type="text" id="email" value="" data-placeholder="Enter your e-mail">
*/
$('input[data-placeholder]').each(function(){
$(this)
.bind('focus', function() {
if ($(this).val() == $(this).data('placeholder'))
$(this).val('');
})
.bind('blur', function() {
if (!$(this).val())
$(this).val($(this).data('placeholder'));
})
.trigger('blur');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment