I really thought this would have been answered years ago, still I did not find any solution:
I want to highlight (i.e. make a colored background) all occurrences of a (sub-)string on an entire HTML page, completely client-side with JavaScript.
Just as you would use Ctrl+F to search inside Google Chrome: When entering the search term, it highlights all the substrings that match my entered term.
Personally, I would walk all elements of the DOM tree, doing some replace
of the search term with something like
<span style="background-color: yellow">MySearchTerm</span>
But I think there must be some more effective way?
My question:
How to use JavaScript (or jQuery) to highlight all substring occurrences inside a HTML page?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…