Created
August 22, 2012 12:39
-
-
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.
This file contains hidden or 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
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