Skip to content

Instantly share code, notes, and snippets.

@afahy
Created October 22, 2009 17:47
Show Gist options
  • Save afahy/216126 to your computer and use it in GitHub Desktop.
Save afahy/216126 to your computer and use it in GitHub Desktop.
Watermark fields
(function($){
$.fn.watermark = function(){
return this.each(function(){
var $this = $(this),
tag = this.nodeName.toLowerCase(),
txt;
if(tag == "input" || tag == "textarea"){
txt = $this.val();
$this.bind("focus.watermark", function(){
if($this.val() == txt){ $this.val(""); }
})
.bind("blur.watermark", function(){
if($this.val() == ""){ $this.val(txt); }
});
}
});
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment