Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gabrielmansour/930205 to your computer and use it in GitHub Desktop.
Save gabrielmansour/930205 to your computer and use it in GitHub Desktop.
jQuery HTML5 placeholder fix
jQuery.placeholder = function() {
var p='placeholder',s='['+p+']';
$(s).live('focus',function() {
var input = $(this);
if (input.hasClass(p)) {
input.val('').removeClass(p);
}
}).live('blur', function() {
var input = $(this);
if (input.val() === '') {
input.addClass(p).val(input.attr(p));
}
}).blur().parents('form').live('submit', function() {
$(this).find(s).each(function() {
var input = $(this);
if (input.hasClass(p)) {
input.val('');
}
});
});
// Clear input on refresh so that the placeholder class gets added back
$(window).unload(function() {
$(s).val('');
});
};
input.placeholder
:color #aaa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment