Skip to content

Instantly share code, notes, and snippets.

@MaciekBaron
Created April 8, 2013 11:24
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 MaciekBaron/5336075 to your computer and use it in GitHub Desktop.
Save MaciekBaron/5336075 to your computer and use it in GitHub Desktop.
A simple fallback for HTML5 placeholders (using jQuery)
if (!("placeholder" in document.createElement("input"))) {
$("[placeholder]").each(function () {
var placeholder = $(this).attr("placeholder");
$(this).val(placeholder).focus(function () {
if ($(this).val() === placeholder) {
$(this).val("");
}
}).blur(function () {
if ($(this).val().length === 0) {
$(this).val(placeholder);
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment