Code:
console.log(t);
console.log('temp[1]='+temp[1]);
res = document.getElementById("labnol");
//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.
Code:
if ( t >= 0)
{
var re = new RegExp("(\\b" + temp[1] + "\\b)", "gim");//pattern for keyword
console.log(re);
// var re0 = new RegExp("[>][^><]*[><]", "gi");//pattern to get textnode
res.innerHTML = res.innerHTML.replace(re, function (text) {
//with each textNode, looking for keyword
return text.replace(re, "<span class=\"search-result\" style=\"background-color:yellow;\">$&</span>");
}