Skip to content

Instantly share code, notes, and snippets.

@albburtsev
Created January 25, 2011 11:04
Show Gist options
  • Save albburtsev/794794 to your computer and use it in GitHub Desktop.
Save albburtsev/794794 to your computer and use it in GitHub Desktop.
Custom placeholder for text input
$.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