1

For example, if I have <p>Hello world</p> and my cursor is on e, how could I know that?

Update

Thank you so much for all of your comments. I don't want to change it, but to get two information: the char, in this case "e" and it's position (x and y). I'll use them for other purposes. I'm also making it for a Chrome extension so that I cannot change the original HTML tags.

j22
  • 71
  • 1
  • 7
  • 1
    What do you mean by "my cursor is on `e`"? – aymericbeaumet May 02 '20 at 17:42
  • What do you want to change it to? – aymericbeaumet May 02 '20 at 17:42
  • 4
    Put every letter in a span and place an onmouseover event handler on it. – Markus Zeller May 02 '20 at 17:43
  • 1
    [How to make each letter in word change on hover](https://stackoverflow.com/questions/24471132) – adiga May 02 '20 at 17:45
  • 2
    You can get some idea from [How to get a word under cursor using JavaScript?](https://stackoverflow.com/questions/2444430/how-to-get-a-word-under-cursor-using-javascript) – palaѕн May 02 '20 at 17:45
  • Does this answer your question? [How to make each letter in word change on hover](https://stackoverflow.com/questions/24471132/how-to-make-each-letter-in-word-change-on-hover) – evolutionxbox May 02 '20 at 17:57
  • Thank you so much for all of your comments. I don't want to change it, but to get two information: the char, in this case "e" and it's position (x and y). I'll use them for other purposes. I'm also making it for a Chrome extension so that I cannot change the original HTML tags. – j22 May 03 '20 at 18:32

1 Answers1

0

You can put every letter in a span element, then add a onmouseoverevent to it.

Like this:

  function func1(){
   document.writeln("H");
  }
  function func2(){
   document.writeln("e");
  }
<!DOCTYPE html>
<html>
<body>
 <p><span onmouseover="func1();">H</span><span onmouseover="func2();">e</span>llo World!</p>
</body>
</html>

Note that it also replaces the text that was already there.