Skip to content

Instantly share code, notes, and snippets.

@arkadylukashov
Created September 17, 2012 06:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arkadylukashov/3735852 to your computer and use it in GitHub Desktop.
Save arkadylukashov/3735852 to your computer and use it in GitHub Desktop.
jqurey placeholder function
/** > placeholderize ['placeholdered' <- класс когда текст в инпуте из плейсхолдера] */
(function($) {
var activeClass = 'placeholdered';
$('[data-placeholder]').each(function(i) {
var placeholder = $(this).data('placeholder');
if (this.value.length == 0) {
this.value = placeholder;
$(this).addClass(activeClass)
}
$(this)
.on('focus', function() {
if (this.value == placeholder) { $(this).val('').removeClass(activeClass); }
})
.on('blur', function() {
if ($.trim(this.value) == '') { $(this).val(placeholder).addClass(activeClass); }
})
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment