Skip to content

Instantly share code, notes, and snippets.

@kferran
Created January 10, 2013 18:34
Show Gist options
  • Save kferran/4504578 to your computer and use it in GitHub Desktop.
Save kferran/4504578 to your computer and use it in GitHub Desktop.
// Placeholder support for IE and older browsers.
// http://www.femgeek.co.uk/html5-placeholders-for-troublesome-browsers-ie-ie9/
$(function() {
if(!$.support.placeholder) {
var active = document.activeElement;
$('textarea').each(function(index, element) {
if($(this).val().length == 0) {
$(this).html($(this).attr('id')).addClass('hasPlaceholder');
}
});
$('input, textarea').focus(function () {
if ($(this).attr('placeholder') != '' && $(this).val() == $(this).attr('placeholder')) {
$(this).val('').removeClass('hasPlaceholder error');
}}).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