Skip to content

Instantly share code, notes, and snippets.

@jimfleming
Created July 20, 2010 17:07
Show Gist options
  • Save jimfleming/483229 to your computer and use it in GitHub Desktop.
Save jimfleming/483229 to your computer and use it in GitHub Desktop.
Default Text jQuery Plugin
(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