Skip to content

Instantly share code, notes, and snippets.

@fredkelly
Created July 5, 2011 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fredkelly/1064558 to your computer and use it in GitHub Desktop.
Save fredkelly/1064558 to your computer and use it in GitHub Desktop.
Quick fix for the HTML5 placeholder="" attribute using jQuery & Modernizr
if (!Modernizr.input.placeholder) {
$("input").each(function(){
if ($(this).val() == "" && $(this).attr("placeholder") != "") {
$(this).val($(this).attr("placeholder"));
$(this).focus(function(){
if ($(this).val() == $(this).attr("placeholder")) $(this).val("");
}); // focus
$(this).blur(function(){
if ($(this).val() == "") $(this).val($(this).attr("placeholder"));
}); // blur
} // if
}); // each
} // if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment