How can I highlight a word/term quicker and smarter?

后端 未结 6 753
误落风尘
误落风尘 2021-02-05 06:27

I have some text:

Hello world, Attack on Titan season two!

Currently, if a user wants to highlight a word/ter

6条回答
  •  滥情空心
    2021-02-05 07:05

    So you are going to have to deal with text ranges and such. I've dealt with this, and it's extremely painful, especially if you have DOM contents like:

    New season of Attack on Titan!

    i.e. text nodes mixed with other DOM elements, such as a span in this case. With this in mind, I'd like to highly recommend the library rangy.js: https://github.com/timdown/rangy

    It's saved me several days of headache when I was making a hashtag highlighting system.

提交回复
热议问题