change the default search box text in SharePoint 2010 using JQuery


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

Use whatever is needed to select the input box. $('#searchBoxOuter td.ms-sbcell input') reflects some custom master page html I have so I used that.


Copy this code and paste it in your HTML
  1. $(function() {
  2.  
  3. var theSearchBox = $('#searchBoxOuter td.ms-sbcell input');
  4. var defaultSearchText = "Search this site";
  5. var preferredSearchText = "Search my custom site name";
  6.  
  7. theSearchBox.val(preferredSearchText); //replace the text initially
  8.  
  9. theSearchBox.blur(function() { //replace the text when the search box loses focus and no value entered
  10. if ($(this).val().indexOf(defaultSearchText) > -1)
  11. $(this).val(preferredSearchText);
  12.  
  13. });
  14.  
  15.  
  16. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.