I have a list of keywords, and then a list of sentences containing these keywords on the page. I would like to make the keyword list available. When a user clicks on a keyword, all occurrences of that keyword are highlighted in sentences.
How can I do this using jQuery or raw Javascript?
The only way I can think of is to wrap every word on the page with a class containing itself as the name of the class. Then make keyword buttons that add a highlight class to the corresponding word classes. This might work, but there seem to be a lot of unnecessary code injections.
Keyword List
<button>this</button> <button>example</button>
suggestions
<span class='word_this'>This</span> <span class='word_is'>is</span> <span class='word_an'>an</span> <span class='word_example'>example</span>.
source share