Skip to content

Instantly share code, notes, and snippets.

@aL3xa
Created April 10, 2012 23:32
Show Gist options
  • Save aL3xa/2355617 to your computer and use it in GitHub Desktop.
Save aL3xa/2355617 to your computer and use it in GitHub Desktop.
Quick and dirty jQuery watermark function
// Quick & dirty watermark function
// inspired by https://github.com/marioestrada/jQuery-Watermark
(function ($){
$.fn.watermark = function(){
var $elems = $(this).filter('textarea, input[type="text"]');
$elems.each(function(i, e){
var $this = $(e);
var title = $this.attr('title') || '';
$this
.show(function(){
$this.val(title);
})
.focus(function(){
$this.val('');
})
.blur(function(){
if ($this.val() == '' || $this.val() == title){
$this.val(title);
}
});
});
}
$(function(){
$('.watermark').watermark();
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment