Skip to content

Instantly share code, notes, and snippets.

@gaboesquivel
Forked from senko/placeholder.js
Created April 2, 2012 23:12
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save gaboesquivel/2287873 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