Skip to content

Instantly share code, notes, and snippets.

@willhalling
Created July 25, 2013 08:20
Show Gist options
  • Save willhalling/6077812 to your computer and use it in GitHub Desktop.
Save willhalling/6077812 to your computer and use it in GitHub Desktop.
Placeholder input text support in IE8/9
// placeholder text support in IE8/IE9
$(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').submit(function () {
$(this).find('.hasPlaceholder').each(function() { $(this).val(''); });
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment