Created
September 17, 2012 06:36
-
-
Save arkadylukashov/3735852 to your computer and use it in GitHub Desktop.
jqurey placeholder function
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
/** > 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