(function($) { $.fn.toggleVal = function(theOptions) { if(!theOptions || typeof theOptions == 'object') { theOptions = $.extend({}, $.fn.toggleVal.defaults, theOptions); } else if(typeof theOptions == 'string' && theOptions.toLowerCase() == 'destroy') { var destroy = true; } return this.each(function() { if(destroy) { $(this).unbind('focus.toggleval').unbind('blur.toggleval').removeData('defText'); return false; } var defText = $(this).val(); $(this).addClass('toggleval').data('defText', defText); $(this).bind('focus.toggleval', function() { if($(this).val() == $(this).data('defText')) { $(this).val(''); } $(this).addClass(theOptions.focusClass); }).bind('blur.toggleval', function() { if($(this).val() == '' && !theOptions.sticky) { $(this).val($(this).data('defText')); } $(this).removeClass(theOptions.focusClass); if($(this).val() != '' && $(this).val() != $(this).data('defText')) { $(this).addClass(theOptions.changedClass); } else { $(this).removeClass(theOptions.changedClass); } }); }); }; })(jQuery);