I want to highlight all the keywords (case insensitive) within a p tag programatically
if the keywords are
var keywords = "hello,thanks, goodbye" // this should be an array
<p>hello world</p>
hello should be highlighted in blue
I think you are looking for the jQuery highlight plugin.
Once you have it loaded, you can just do something like this:
var words = "hello,thanks, goodbye";
var keywords = words.split(',');
for(var x = 0; x < keywords.length; x++) {
$(selector).highlight($.trim(keywords[x]));
}
Where selector is what element in the document you want to look for. If you want it to be done to the entire page, just put 'body'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With