By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,604 Members | 858 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,604 IT Pros & Developers. It's quick & easy.

Replace hightlighted word in span tag

P: 1
Expand|Select|Wrap|Line Numbers
  1. console.log(t);
  2. console.log('temp[1]='+temp[1]);
  3.   res = document.getElementById("labnol");
  4.  
  5. //var d = document.getElementsByTagName("body")[0];

Hey i ve wriiten code for hightighting a particular word in javascript.But m not getting how to replace all the hightighted word with dynamic words.
This is the code have written for highlighting words.

Expand|Select|Wrap|Line Numbers
  1. if ( t >= 0)
  2. {
  3.    var re = new RegExp("(\\b" + temp[1] + "\\b)", "gim");//pattern for keyword
  4. console.log(re);
  5.  
  6.   // var re0 = new RegExp("[>][^><]*[><]", "gi");//pattern to get textnode
  7.  
  8.  
  9.    res.innerHTML = res.innerHTML.replace(re, function (text) {
  10.  
  11.         //with each textNode, looking for keyword
  12.       return text.replace(re, "<span class=\"search-result\" style=\"background-color:yellow;\">$&</span>");
  13. }
May 21 '14 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.