Advertisement
akeif

Change input field placeholder text with jQuery

Mar 3rd, 2014
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This script is an update of http://www.perfectline.co/2009/10/change-input-field-placeholder-with-jquery/
  2. // If you need input[type=password] support use http://pastebin.com/xX5U1vpK
  3.  
  4. $(document).ready( function() {
  5.     $(".placeholder").each( function( ) {
  6.    
  7.         var elem = $(this);
  8.         var text = elem.attr('rel');
  9.  
  10.         if ( elem.val() === '' )
  11.             elem.val( text );
  12.    
  13.         elem.focus( function() {
  14.             if ( elem.val() === text )
  15.                 elem.val('');
  16.         });
  17.  
  18.         elem.blur( function() {
  19.             if ( elem.val() === '' )
  20.                 elem.val( text );
  21.         });
  22.        
  23.         var form = elem.parents('form:first');
  24.  
  25.         form.submit( function() {
  26.             if (elem.val() === text)
  27.                 elem.val("");
  28.         });
  29.        
  30.     });
  31. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement