Is there a way in which I can detect when specifically text is being hovered over, rather than the entire div/span?
-
I don't think you can, I believe it has to be an element such as a span. Can't you just wrap the text in a span tag? – MattP Feb 26 '12 at 22:08
-
Related: http://stackoverflow.com/questions/2444430/how-to-get-a-word-under-cursor-using-javascript. – pimvdb Feb 26 '12 at 22:11
-
I could of course, this was more just for educational purposes and I couldn't find any information on it. – Ian Feb 26 '12 at 22:13
-
Nope, but you can target the element, then check if it has a certain content, and if so perform the hover action, or you could just wrap the text in a span. – adeneo Feb 26 '12 at 22:13
-
To clarify the question are you asking if there is a Javascript/JQuery way to determine if you are hovering over text, the same way that triggers the cursor to go to a text selection cursor within a browser? – MattP Feb 26 '12 at 22:19
1 Answers
You can use the event.target that triggered the hover over event, assuming you have access to the event object.
EDIT:
This is overkill, but can be fun:
When you hover over a span/div, you can split all the text in it and wrap each character with span tags that serve LITERALLY no other purpose other than to tell you which word or letter has been hovered over.
I can't see any useful reason to do this, but if you have such a desire, then this is a temporary and relatively quick (text-length depending) way to determine which letter or letters someone is hovering over in a set of text.
I did this for another project where the desire was to trigger a way to do translations of certain specific words in a 'very' length text document so that people learning a language could save words for later translation - if this is close to your context, then this might work, otherwise, please explain more.

- 2,533
- 1
- 16
- 33