Posted By

sguduru on 05/04/11


Tagged

jquery text highlight


Versions (?)

Highlight Search Terms on page using jQuery


 / Published in: jQuery
 

URL: http://www.techtricky.com/highlight-text-with-jquery/

  1. var template: '$1<span class="highlight">$2</span>$3';
  2. var pattern = new RegExp('(>[^<.]*)(' + keywords + ')([^<.]*)', "ig");
  3.  
  4. var content = $('body').html();
  5. $('body').html(content.replace(pattern, template));

Report this snippet  

You need to login to post a comment.