Created
August 14, 2012 11:44
-
-
Save aramk/3348598 to your computer and use it in GitHub Desktop.
Adds placeholder to browsers that don't support it (IE)
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
// Adds placeholder to browsers that don't support it (IE) | |
$(document).ready(function() { | |
if(!$.support.placeholder) { | |
var sel = "*[placeholder]"; | |
var addPlaceholders = function () { | |
if ($(this).attr('placeholder') && $(this).val() == "") { | |
$(this).val($(this).attr('placeholder')); | |
$(this).addClass('placeholder'); | |
} | |
}; | |
$(sel).focus(function () { | |
if ($(this).hasClass('placeholder')) { | |
$(this).val(''); | |
$(this).removeClass('placeholder'); | |
} | |
}).blur(addPlaceholders).each(addPlaceholders); | |
$('form').submit(function () { | |
$('.placeholder', this).each(function () { | |
$(this).val(''); | |
$(this).removeClass('placeholder'); | |
}); | |
return true; | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment