Created
April 19, 2012 23:04
-
-
Save hsquareweb/2424772 to your computer and use it in GitHub Desktop.
jQuery: Placeholder Fallback For Modernizer
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
//Placeholders fallback | |
$(function() { | |
// check placeholder browser support | |
if (!Modernizr.input.placeholder) { | |
// set placeholder values | |
$(this).find('[placeholder]').each(function() { | |
if ($(this).val() == '') { $(this).val( $(this).attr('placeholder') ); } | |
}); | |
// focus and blur of placeholders | |
$('[placeholder]').focus(function() { | |
if ($(this).val() == $(this).attr('placeholder')) { | |
$(this).val(''); | |
$(this).removeClass('placeholder'); | |
} | |
}).blur(function() { | |
if ($(this).val() == '' || $(this).val() == $(this).attr('placeholder')) { | |
$(this).val($(this).attr('placeholder')); | |
$(this).addClass('placeholder'); | |
} | |
}); | |
// remove placeholders on submit | |
$('[placeholder]').closest('form').submit(function() { | |
$(this).find('[placeholder]').each(function() { | |
if ($(this).val() == $(this).attr('placeholder')) { | |
$(this).val(''); | |
} | |
}) | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment