Created
May 20, 2011 14:47
-
-
Save garyharan/983059 to your computer and use it in GitHub Desktop.
Make older browsers act as do modern browsers in regards to placeholder in inputs
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
$(function(){ | |
if ("placeholder" in document.createElement( "input" )){ return } | |
$('input[placeholder]').each(function(){ | |
$(this).val($(this).attr('placeholder')).css('color', '#999') | |
}).focus(function(){ | |
var placeholder = $(this).attr('placeholder') | |
$(this).val( placeholder == $(this).val() || $(this).val() == '' ? '' : $(this).val() ).css('color', '#333') | |
}).blur(function(){ | |
var placeholder = $(this).attr('placeholder') | |
if ($(this).val() == '') { | |
$(this).val(placeholder).css('color', '#999') | |
} | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Same thing in vanilla javascript!