Posted By

javifr on 10/29/10


Tagged

jquery


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Tyster


Clear default on click


 / Published in: JavaScript
 

  1. (function($){
  2. $.fn.clearDefault = function(){
  3. return this.each(function(){
  4. var default_value = $(this).val();
  5. $(this).focus(function(){
  6. if ($(this).val() == default_value)
  7. $(this).val("");
  8. });
  9. $(this).blur(function(){
  10. if ($(this).val() == "")
  11. $(this).val(default_value);
  12. });
  13. });
  14. };
  15. })(jQuery);
  16.  
  17. // How to use it: $('input').clearDefault();
  18.  

Report this snippet  

You need to login to post a comment.