Created
January 25, 2011 11:04
-
-
Save albburtsev/794794 to your computer and use it in GitHub Desktop.
Custom placeholder for text input
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
$.placeHolder = function(input, text) { | |
var _input = $(input), | |
_class = 'placeholder'; | |
_value = _input.val(); | |
_input | |
.focus(function() { | |
_value = $(this).val(); | |
$(this) | |
.removeClass(_class) | |
.val(_value == text ? '' : _value) | |
; | |
}) | |
.blur(function() { | |
_value = $(this).val(); | |
$(this) | |
.toggleClass(_class, _value === '') | |
.val(_value === '' ? text : _value) | |
; | |
}) | |
.data('placeholder', text) | |
.trigger('blur') | |
; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment