I have a div of text. I want to highlight some of this text stored in a variable using RegExp and span. the text to be highlighted is unknown at run time.
var t = $("#highlightOutput").html(); //sentence
var s = t.search(hStr);//what shd be replaced
var query = new RegExp(s, "g");
console.log(s);
t = t.replace(query, "<span class='highlight'>"+s+ "</span>"); //problem is here
//how to write a regex code to highlight text stored in s.
$("#highlightOutput").html(t);