Created
July 20, 2010 17:07
-
-
Save jimfleming/483229 to your computer and use it in GitHub Desktop.
Default Text jQuery Plugin
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
(function($) { | |
$.fn.defaultText = function(settings) { | |
var defaults = { 'color' : '#ccc', | |
'default_text' : 'Default Text' | |
}; | |
if (settings) $.extend(defaults, settings); | |
this.each(function() { | |
$this = $(this); | |
$this.css('color', defaults.color); | |
$this.val(defaults.default_text); | |
$this.focus(function() { | |
$this.css('color', '#000'); | |
if ($this.val() == defaults.default_text) | |
$this.val(''); | |
}); | |
$this.blur(function() { | |
if ($this.val() == defaults.default_text || $this.val() == '') { | |
$this.css('color', defaults.color); | |
$this.val(defaults.default_text); | |
} | |
}); | |
}); | |
return this; | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment