Posted By

vagrantradio on 02/16/10


Tagged

clear search input focus


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

pauloc


CLEAR INPUT ON FOCUS FUNCTION


 / Published in: jQuery
 

Clears input or search field on focus.

  1. $(document).ready(function() {
  2. //attach function to input and make text grayed out on page load
  3. textReplacement($('#query').css("color", "#999"));
  4. });
  5.  
  6. // the function:
  7. function textReplacement(input){ //input focus text function
  8. var originalvalue = input.val();
  9. input.focus( function(){
  10. if( $.trim(input.val()) == originalvalue ){ input.val('').css("color", "#000"); }
  11. });
  12. input.blur( function(){
  13. if( $.trim(input.val()) == '' ){ input.val(originalvalue).css("color", "#999"); }
  14. });
  15. }

Report this snippet  

You need to login to post a comment.