Reputation: 65123
If I have
<div>
hello
</div>
and I select 'hello' with my cursor, the start index is 6, end is 11 (inclusive).
Is there a way to get this information cross-browser with JavaScript or jQuery?
Upvotes: 3
Views: 414
Reputation: 10305
If you've jQuery included you can do:
var selectionText = $(window.getSelection().getRangeAt(0).cloneContents()).text()
Upvotes: 1