469,344 Members | 6,274 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,344 developers. It's quick & easy.

Replace hightlighted word in span tag

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
0 958

Post your reply

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

Similar topics

6 posts views Thread by Aaron | last post: by
20 posts views Thread by hagai26 | last post: by
reply views Thread by tthompson2007 | last post: by
3 posts views Thread by gregpinero | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.