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


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



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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.