Skip to content

Instantly share code, notes, and snippets.

@tybruffy
Last active December 14, 2015 19:19
Show Gist options
  • Save tybruffy/5135883 to your computer and use it in GitHub Desktop.
Save tybruffy/5135883 to your computer and use it in GitHub Desktop.
IE Placeholder support
if(!$.support.placeholder) {
var active = document.activeElement;
$('[type="text"], [type="email"], textarea').focus(function () {
if ($(this).attr('placeholder') != '' && $(this).val() == $(this).attr('placeholder')) {
$(this).val('').removeClass('hasPlaceholder');
}
}).blur(function () {
if ($(this).attr('placeholder') != '' && ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))) {
$(this).val($(this).attr('placeholder')).addClass('hasPlaceholder');
}
});
$('[type="text"], [type="email"], textarea').blur();
$(active).focus();
$('form').submit(function () {
$(this).find('.hasPlaceholder').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