Is it possible to highlight a specific fragment of text using text range or another approach? I have a text block, for example:
<div id="test">abcdefghij</div>
I have successfully used text range to highlight text in yellow color (as seen in an example on SO). Is it possible to add an event listener for mouseover on the highlighted text? I would like to trigger something when the user hovers over 'cdefg'. Here is a working example on jsfiddle:
http://jsfiddle.net/8mdX4/673/
I welcome any ideas and suggestions.
Best regards.
Edit:
After posting the question, I would like to share my approach. I am using the focusNode property of the selection because commonAncestorContainer retrieves the container of all nodes, not just the currently selected node. Here is a demonstration: http://jsfiddle.net/zono/Q3ptC/2/ When hovering over the yellow text, a tooltip (content of title property) is displayed.