Skip to content

Instantly share code, notes, and snippets.

@cwardzala
Created November 15, 2011 00:16
Show Gist options
  • Save cwardzala/1365664 to your computer and use it in GitHub Desktop.
Save cwardzala/1365664 to your computer and use it in GitHub Desktop.
HTML5 Placeholder fallback.
function hasPlaceholderSupport() {
var input = document.createElement('input');
return ('placeholder' in input);
}
(function () {
if (hasPlaceholderSupport() === false) {
$('input[placeholder]').each(function () {
var $this = $(this), placeholder = $this.attr('placeholder');
$this.val(placeholder).focus(function() {
if ($this.val() === placeholder) {
$this.val('');
}
}).blur(function () {
if ($this.val() === '') {
$this.val(placeholder);
}
});
});
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment