Skip to content

Instantly share code, notes, and snippets.

@iamntz
Created May 2, 2011 14:58
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 iamntz/c8e3d2577c9e95fc48e1 to your computer and use it in GitHub Desktop.
Save iamntz/c8e3d2577c9e95fc48e1 to your computer and use it in GitHub Desktop.
placeholder.v2
function enablePlaceholderSupport(b){var d=jQuery,b=b||"body",c=document.createElement("input"),e=("placeholder" in c),a=function(f){if(d(f).val()===d(f).data("placeholder")){d(f).val("")}};if(!e){d("input[placeholder]",b).each(function(){var f=d(this),h=f.attr("placeholder"),g=d.trim(this.value);if(typeof f.data("placeholder")!=="undefined"){return}f.data("placeholder",h);if(g==""){d(this).val(h).addClass("placeholder")}f.bind("focus.ntz_placeholder",function(){if(this.value==d(this).data("placeholder")){d(this).val("").removeClass("placeholder")}}).bind("blur.ntz_placeholder",function(){if(this.value.length===0){d(this).val(h).addClass("placeholder")}})});d("form").bind("submit.ntz_placeholder",function(){d("input[placeholder]",this).each(function(){a(this)})});d(window).bind("unload.ntz_placeholder",function(){a(d("input[placeholder]",this))})}};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment