Created
April 10, 2012 23:32
-
-
Save aL3xa/2355617 to your computer and use it in GitHub Desktop.
Quick and dirty jQuery watermark function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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