Highlight Search Terms on page using jQuery


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



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

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.