Posted By

Fitzgenius on 06/18/11


Tagged

form clear input jquery restore


Versions (?)

jQuery Text Clear and Restore


 / Published in: jQuery
 

This should enable you to clear elements such as search boxes effectively whilst maintaining usability.

Enjoy!

  1. $('input[type=text]').each( function() {
  2. var input = $(this); var inputVal = input.val();
  3. input.focus( function(){ if( input.val() != inputVal ) { return false; } input.val(''); } );
  4. input.blur( function(){ if( input.val() == '' ) { input.val( inputVal ); } } );
  5. } );

Report this snippet  

You need to login to post a comment.