title: Not Removing the previous Highlighted (selected) Text while searching the text from page
body: <p>I am doing the search functionality of text .I am facing one problem actually first time i search it is working fine .But when i search again and press search it is showing the previous first search highlighted text.Not showing the search text.How to solve that issue.
  Here is my code.
  <a href="http://jsfiddle.net/ravi1989/z7fjW/143/" rel="nofollow">http://jsfiddle.net/ravi1989/z7fjW/143/</a></p>
  
  <pre><code>function searchAndHighlight(searchTerm, selector) {
      if(searchTerm) {
          //var wholeWordOnly = new RegExp("\\g"+searchTerm+"\\g","ig"); //matches whole word only
          //var anyCharacter = new RegExp("\\g["+searchTerm+"]\\g","ig"); //matches any word with any of search chars characters
          var selector = selector || "#bodyContainer";                             //use body as selector if none provided
          var searchTermRegEx = new RegExp(searchTerm,"ig");
          var matches = $(selector).text().match(searchTermRegEx);
          if(matches) {
  $('.highlighted').removeClass('highlighted');     //Remove old search highlights
                  $(selector).html($(selector).html().replace(searchTermRegEx, "&lt;span class='match'&gt;"+searchTerm+"&lt;/span&gt;"));
             $('.match:first').addClass('highlighted');
              $('#next').on('click',i=1, function()
          {   alert(i); 
              $('.match').removeClass('highlighted');                                                                   $('.match').eq(i).addClass('highlighted');
  
            i=i+1; 
          k=i-2;
           alert(i);
       }); 
                    $('#previous').on('click',k=1, function()
          {   alert(k);
              $('.match').removeClass('highlighted');                                                                   $('.match').eq(k).addClass('highlighted');         
            k=k-1;
              i=k+2;
       });
  
  
  
  
              if($('.highlighted:first').length) {             //if match found, scroll to where the first one appears
                  $(window).scrollTop($('.highlighted:first').position().top);
              }
              return true;
          }
      }
      return false;
  }
  $(document).ready(function() {
      $('#search-button').on("click",function() {
          if(!searchAndHighlight($('#search-term').val())) {
              alert("No results found");
          }
      });
  });
  </code></pre>