Skip to content

Instantly share code, notes, and snippets.

@gaboesquivel
Forked from senko/placeholder.js
Created April 2, 2012 23:12
Show Gist options
  • Save gaboesquivel/2287873 to your computer and use it in GitHub Desktop.
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