I have looked at this question and many similar answers but they aren't useful to me, because they give plain text of selected section.I want to get index of start & end points based on parent Node not its children.
For example given the following snippet:
<p>
hello,
<span> i </span>
am
<span> here </span>
</p>
I want to select "i am he" and get these numbers : [7,14] which 7 is index of 'i' and 14 is index of 'e' in "hello,i am here".
when I get selected text by document.getSelection()
, start point is 0 & end point is 1(because of span tags.)
how can I get start and end points just based on <p>
tag (not <p>
& <span>
s ) and in numerical form?