I have an HTML element with only visible text inside. This example is a
,
In many cases, a possible solution can be to add zero-width space character (U+200B) between each char of the content of the tag. Then using javascript window.getSelection().focusOffset + some simple computations does the job.
Sample html code (including zero-width space characters):
This is a simple example.
Sample javascript code:
Seems to work widely, even on internet explorer!
jsFidle: http://jsfiddle.net/by1a9pfm/