I have two span elements inside of p tag. While selecting some text in that p I need to get the start and end offset of selected value using window.getSelection().
My expectation is that while selecting the second span text like 'country', the start offset value would be 28 and end offset would be 34 without considering its immediate parent. However the actual value of start offset is 10 and end offset is 16.
How can I meet my expected values?
<p style="margin: 0px;">
<span>Welcome to India which</span>
<span>
<span>was great country for tourist places</span>
</span>
</p>
private onKeyUp(event: any): void {
let labelSelection = window.getSelection ? window.getSelection() : document.getSelection();
let range: any = this.labelSelection.getRangeAt(0);
}