Created
February 18, 2011 05:28
-
-
Save anonymous/833295 to your computer and use it in GitHub Desktop.
placeholder
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
var fakeInput=document.createElement("input"),placeHolderSupport=("placeholder" in fakeInput),clearValue=function(a){if($(a).val()===$(a).data("placeholder")){$(a).val("")}};if(!placeHolderSupport){$("input[placeholder], textarea[placeholder]").each(function(){var a=$(this),c=a.attr("placeholder"),b=this.value;if(this.type.toLowerCase()=="file"){return}a.data("placeholder",c);if(b==""){this.value=c}else{a.addClass("placeholder")}a.bind("focus blur",function(f){var d=this;switch(f.type){case"blur":default:if(d.value.length===0){$(d).val(c).addClass("placeholder")}break;case"focus":if(d.value==c){d.value=""}break}})});$("form").bind("submit",function(){clearValue($("input[placeholder]",this))});$(window).bind("unload",function(){clearValue($("input[placeholder]",this))})}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment