Skip to content

Instantly share code, notes, and snippets.

@theY4Kman
Created August 22, 2012 12:39
Show Gist options
  • Save theY4Kman/3425188 to your computer and use it in GitHub Desktop.
Save theY4Kman/3425188 to your computer and use it in GitHub Desktop.
Simple <input> hints jQuery plug-in. Adds class 'hint' when the hint is active. It's smart. TODO: display password fields as text when hint is active.
jQuery.fn.inputHints = function() {
function hintIfBlank(elem)
{
if (elem.val() == '')
elem.val(elem.attr('title')).addClass('hint').data('hint', true);
}
$(this)
.data('hint', false)
.focus(function() {
if ($(this).val() == $(this).attr('title') && $(this).data('hint'))
$(this).val('').removeClass('hint').data('hint', false);
})
.blur(function() {
hintIfBlank($(this));
});
$(this).each(function(index, value) {
hintIfBlank($(this));
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment