Skip to content

Instantly share code, notes, and snippets.

@charliecm
Created October 8, 2013 18:31
Show Gist options
  • Save charliecm/6889305 to your computer and use it in GitHub Desktop.
Save charliecm/6889305 to your computer and use it in GitHub Desktop.
Fallback for input placeholder. Uses a .is-placeholder class to style placeholder text.
if(!Modernizr.input.placeholder){
$('input[placeholder], textarea[placeholder]').each(function() {
$(this).val($(this).attr('placeholder'));
$(this).addClass('is-placeholder');
}).blur(function() {
if ($(this).val() === '') {
$(this).val($(this).attr('placeholder'));
$(this).addClass('is-placeholder');
}
}).focus(function() {
if ($(this).val() === $(this).attr('placeholder')) {
$(this).val('');
$(this).removeClass('is-placeholder');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment