jQuery Text Clear and Restore


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

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

Enjoy!


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


Comments


You need to login to view comments.