/ Published in: jQuery
This function loops through a result set of inputs and for each result, it clears the default value onfocus and restores the default if the value is empty onblur.
Expand |
Embed | Plain Text
(function($){ $.fn.clearDefault = function(){ return this.each(function(){ var default_value = $(this).val(); $(this).focus(function(){ if ($(this).val() == default_value) $(this).val(""); }); $(this).blur(function(){ if ($(this).val() == "") $(this).val(default_value); }); }); }; })(jQuery); // Usage: $('input.clear-default').clearDefault();
You need to login to post a comment.
