Skip to content

Instantly share code, notes, and snippets.

@dave1010
Created November 22, 2012 11:15
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 dave1010/4130621 to your computer and use it in GitHub Desktop.
Save dave1010/4130621 to your computer and use it in GitHub Desktop.
HTML5 placeholder polyfill
if (!Modernizr.input.placeholder) {
// Old IE doesn't support the placeholder attribute on <input>
// TODO: placeholder colour and remove when submitting form
$(function() {
$('input[placeholder]').each(function() {
var ths = $(this), placeholder = ths.attr('placeholder');
if (!ths.val()) {
ths.val(placeholder);
}
ths.focus(function() {
if (ths.val() === placeholder) {
ths.val('');
}
}).blur(function() {
if (!ths.val()) {
ths.val(placeholder);
}
});
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment