Created
October 8, 2013 18:31
-
-
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.
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
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