Skip to content

Instantly share code, notes, and snippets.

@iamntz
Created May 2, 2011
Embed
What would you like to do?
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