Created
November 15, 2011 00:16
-
-
Save cwardzala/1365664 to your computer and use it in GitHub Desktop.
HTML5 Placeholder fallback.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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