Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
placeholder
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