Skip to content

Instantly share code, notes, and snippets.

@nessthehero
Created March 20, 2014 18:58
Show Gist options
  • Save nessthehero/9671260 to your computer and use it in GitHub Desktop.
Save nessthehero/9671260 to your computer and use it in GitHub Desktop.
Placeholder polyfill
// Placeholder polyfill
if (!Modernizr.input.placeholder) {
$('input[placeholder]:not(.ph), textarea[placeholder]:not(.ph)').each(function () {
var place = $(this).attr('placeholder');
$(this).attr('value', place);
$(this).bind('focus', function () {
if ($.trim($(this).attr('value')) === place) {
$(this).attr('value', '');
}
});
$(this).bind('blur', function () {
if ($.trim($(this).attr('value')) === '') {
$(this).attr('value', place);
}
});
$(this).addClass('ph');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment