Assume I have an editable div which contains these lines:
How to retrieve the position of ‘w’ in the text ?
I can’t use:
window.getSelection().anchorOffset;
Because this gets the position in the line, but not in text, that is 0 instead of 5.
I prefer not to use:
element.innerText.indexOf(selectedText);
Because it may retrieve similar texts.
2
Answers
You can see explanation for some of the terms on Laimonas answer
Your anchor offset should be 6.