One-click clearing of default input text values


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.