Posted By

jurajhilje on 04/19/11


Tagged

search input jquery


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Kurt


Wordpress and Joomla - like search input (remove default value on focus)


 / Published in: jQuery
 

  1. // Javascript
  2. var $searchInput = $('#search-input'),
  3. defaultSearchInputValue = $searchInput.attr('value');
  4.  
  5. $searchInput
  6. .focus(function()
  7. {
  8. if($(this).attr('value') == defaultSearchInputValue) $(this).attr('value', '');
  9. })
  10. .blur(function()
  11. {
  12. if($(this).attr('value') == '') $(this).attr('value', defaultSearchInputValue);
  13. });
  14.  
  15. // HTML
  16. <input type="text" id="search-input" value="Search" />

Report this snippet  

You need to login to post a comment.