Skip to content

Instantly share code, notes, and snippets.

@nateluzod
Created June 25, 2011 21:23
Show Gist options
  • Save nateluzod/1046914 to your computer and use it in GitHub Desktop.
Save nateluzod/1046914 to your computer and use it in GitHub Desktop.
Placeholder support for older browsers
$.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"});
};
});
}
}
@nateluzod
Copy link
Author

Requires modernizr to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment