monecchi

jQuery clear text input / HTML5 input fields on focus

Feb 22nd, 2014
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.67 KB | None | 0 0
  1. jQuery(document).ready(function($){
  2. $.fn.defaultValue = function(){
  3.          
  4.          return this.each(function(){
  5.             var default_value = $(this).val();
  6.             var $this = $(this);
  7.    
  8.             $this.focus( function() {
  9.  
  10.                 if ($this.val() == default_value) $(this).val("");
  11.                 });
  12.             $this.blur( function() {
  13.                 if ($this.val().length == 0){
  14.                     $this.val(default_value);
  15.                 }
  16.             })            
  17.          });
  18.          };
  19. $('input[type=text], textarea, input[type=email], input[type=tel], input[type=number], input[type=password]').defaultValue();
  20.  });
Advertisement
Add Comment
Please, Sign In to add comment