How can I highlight every word in jquery so that I can give a definition for each word?

What I'm trying to do is let the user scroll any word on the web page, and when the mouse moves over the word, it is highlighted (I know I can use the hover to do this). However, I do not know how to select individual words from a paragraph. The ultimate goal is to allow the user to click on a word, and the definition appears above the word, but I think I can understand it as soon as I can hover over individual words.

0
source share
2 answers

There is no way in Javascript to do this, the smallest thing you can interact with is, in general, a DOM element. So you can technically wrap every word inside <span>, but that seems to have seriously gone too far and probably also had a big impact on performance.

Instead, what most sites that provide this functionality do, they make a popup pop-up whenever you select text ( see this question for some code to get the current selection ).

Personally, I find this really annoying (e.g. nytimes.com does this, for example), but it is possible that only I ...

+2
source

- , NYtimes, Select Link JQuery, , . Confer .

+1

Source: https://habr.com/ru/post/1771023/


All Articles