Skip to content

Instantly share code, notes, and snippets.

Created February 18, 2011 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/833295 to your computer and use it in GitHub Desktop.
Save anonymous/833295 to your computer and use it in GitHub Desktop.
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