I’m trying to highlight the text in HTML using jQuery and I keep getting this error when I convert each word in the array to a Regular Expression. At the same time, I get some of the words highlighted.
[Uploading: image.png…](This is how it’s currently looking.)
The code is
words.forEach(word => {
word.trim()
var wo = new RegExp(word, "i")
console.log(wo)
$('body').html($('body').html().replace(wo, "<span class = 'highlight'>" + word + "</span>"));
});
Thanks in advance