I got the following HTML:
<div id="editable_phrase">
My
<span style="background-color: #19FC49;"> first</span>
<span style="background-color: #09AC20;"> first</span> //note 2 firsts here
<span style="background-color: #D2C3EA;"> phrase</span>
</div>
And the original phrase that is - My first phrase
I need to find a position of a first letter of a selected word in my original phrase. So if I select (highlight with a mouse) phrase
, I need to get 10 (or whatever it is). I tried to use charAt()
or window.getSelection
but still getting wrong results.
Moreover, if I select the same word but in different positions (like inm my example above where there are 2 first
words) I get the same result as it finds the position of the first word while I need the second one.
I can use jQuery. Any ideas would be welcome. Thank you.