Skip to content

Instantly share code, notes, and snippets.

@codeguy
Created December 9, 2013 15:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save codeguy/7874306 to your computer and use it in GitHub Desktop.
Save codeguy/7874306 to your computer and use it in GitHub Desktop.
Add placeholder attribute fallback for older browsers
placeholderSupport = ("placeholder" in document.createElement("input"));
if (placeholderSupport === false) {
$('[placeholder]').each(function () {
var $input = $(this),
placeholder = $input.attr('placeholder');
$input
.val(placeholder)
.focus(function () {
if ($input.val() === placeholder) {
$input.val('');
}
})
.blur(function () {
if ($input.val() === '') {
$input.val(placeholder);
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment