I am trying to find the selection index of the caret inside a editable div that has nested nodes in it.
Example ( | is the cursor):
<div contenteditable="true">1234<span>5678|9</span></div> //Returns 4
I want the index of all the characters in the div, so the above example should return 8.
This is what I'm using at the moment.
var sel = window.getSelection();
return sel.anchorOffset;
I have tried using commonAncestor, and other selection & range methods, but I am unsure how to find this.