Getting text under the mouse pointer

I am writing a browser add-on and want to get the word (s) that the user currently hovers through Javascript.

+3
source share
3 answers

There is no good universal function for this. If you specify which browser you add to, a specific workaround may occur. When I came across this problem in the past, I had to resort to a request to double-click a word (then you can detect a double click, get highlighted and reset back).

+1
source

, <span> mouseover , target/srcElement , , . : ; CSS; , .

+1

My assumption is that you cannot do this if each word is not in its own container, for example, etc., and you have declared an onmouseover handler for this. A simpler approach is to use the currentSelection element when the user double-clicks or selects a piece of text in the browser. To do this, you can write on mouse click / double click events.

0
source

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


All Articles