Skip to content

Instantly share code, notes, and snippets.

@johnnyfreeman
Created July 28, 2011 13:44
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 johnnyfreeman/1111579 to your computer and use it in GitHub Desktop.
Save johnnyfreeman/1111579 to your computer and use it in GitHub Desktop.
Placeholder - Just a little js to backup html5's placeholder attribute.
(function($){
$.fn.placeHolder = function() {
// check for placeholder attribute support in current browser
var nativeSupport = "placeholder" in document.createElement("input");
var restorePlaceHolder = function() {
if (this.value == "") {
$(this).addClass('inactive');
if (!nativeSupport) this.value = this.placeholder;
};
};
var clearText = function() {
$(this).removeClass('inactive');
if (!nativeSupport && this.value == this.placeholder) this.value = "";
};
return this.focus(clearText).blur(restorePlaceHolder).blur();
};
// attach to elements using the html5 placeholder attribute
$('input[placeholder],textarea[placeholder]').placeHolder();
})(jQuery);
(function(a){a.fn.placeHolder=function(){var d=this.placeholder;var e=this.value;var f="placeholder" in document.createElement("input");var c=function(){if(this.value==""){a(this).addClass("inactive");if(!f){e=d}}};var b=function(){a(this).removeClass("inactive");if(!f&&e==d){e=""}};return this.focus(b).blur(c).blur()};a("input[placeholder],textarea[placeholder]").placeHolder()})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment