-
-
Save gabrielmansour/930205 to your computer and use it in GitHub Desktop.
jQuery HTML5 placeholder fix
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
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(''); | |
}); | |
}; |
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
input.placeholder | |
:color #aaa |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment