How to highlight all text occurrences in a HTML page with JavaScript?

后端 未结 4 1500
逝去的感伤
逝去的感伤 2020-12-09 09:40

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

4条回答
  •  孤城傲影
    2020-12-09 10:05

    The best option for doing this is usually, somewhat surprisingly, to not do it.

    Rely instead on the built-in search feature of the web browser: This ensures that users have a consistent experience, and saves you a lot of trouble in having to double the work that has already been done to allow for this.

提交回复
热议问题