Skip to content

Instantly share code, notes, and snippets.

@aramk
Created August 14, 2012 11:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aramk/3348598 to your computer and use it in GitHub Desktop.
Save aramk/3348598 to your computer and use it in GitHub Desktop.
Adds placeholder to browsers that don't support it (IE)
// 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