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

后端 未结 6 749
误落风尘
误落风尘 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:01

    You cannot set events to Text, but can set events to Html Elements. Put each word inside a div element and add an event onmouseover that changes div to a new highlighted state using css.

    Steps:

    1. Use split to get words into array.
    2. Iterate words and put it into a div.
    3. Iterate divs and set it an event that's change the div to a css class .highlight.

    That's it.

提交回复
热议问题