Created
June 25, 2011 21:23
-
-
Save nateluzod/1046914 to your computer and use it in GitHub Desktop.
Placeholder support for older browsers
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
$.fn.supportPlaceholder = function(){ | |
if(!Modernizr.input.placeholder) { | |
// Populate field with placeholder text | |
var placeholderText = $(this).attr("placeholder"); | |
$(this).val(placeholderText).css({"color" : "#999"}); | |
// Clear text if they focus | |
$(this).focus(function(){ | |
$(this).val("").css({"color" : "#333"}) | |
}); | |
// If value is still empty when they change focus, reset | |
$(this).blur(function(){ | |
if(!$(this).val()){ | |
$(this).val(placeholderText).css({"color" : "#999"}); | |
}; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires modernizr to work.