Created
May 7, 2014 20:02
-
-
Save benytocarlo/528d264cc0252212a6fa to your computer and use it in GitHub Desktop.
Placeholder IE Fix
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
jQuery(function() { | |
jQuery.support.placeholder = false; | |
test = document.createElement('input'); | |
if('placeholder' in test) jQuery.support.placeholder = true; | |
}); | |
// This adds placeholder support to browsers that wouldn't otherwise support it. | |
$(function() { | |
if(!$.support.placeholder) { | |
var active = document.activeElement; | |
$(':text').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'); | |
} | |
}); | |
$(':text').blur(); | |
$(active).focus(); | |
$('form:eq(0)').submit(function () { | |
$(':text.hasPlaceholder').val(''); | |
}); | |
} | |
}); | |
$(document).ready(function(){ | |
$('[placeholder]').parents('form').submit(function() { | |
$(this).find('[placeholder]').each(function() { | |
var input = $(this); | |
if (input.val() == input.attr('placeholder')) { | |
input.val(''); | |
} | |
}) | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment