I\'m trying to turn a set of keywords into links on my site. I am currently using this code which will turn one keyword into a link. However, now I want to expand it to have sev
Do the replacement in a loop. You can use $&
in the replacement to refer to the text that was matched.
var keywords = ['wedding stationery', 'something else', 'other keyword'];
var thePage = $("body");
var theHtml = thePage.html();
for (i = 0; i < keywords.length; i++) {
theHtml = theHtml.replace(new RegExp(keywords[i], 'ig'),
'$&');
}
thePage.html(theHtml);
DEMO