Get start and end of a selection using javascript
问题 i have an html string like this: <div id="div">Hi how are<span>you?</span> Fine</div> The text will appear "Hi how are you? Fine" . I would like to select a part of the string using mouse and get the beginning and the end of the selection looking from the full text string. For example, if i select "you", i would like to obtain start=11 and end=14; if i select "are you?", i would like to obtain start=7 and end=15. I wrote this to obtain the selection: function getSel() { console.log(navigator