-
-
Save gaboesquivel/2287873 to your computer and use it in GitHub Desktop.
HTML input field placeholder handling
This file contains 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
/* 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