How can I get the index of selected text in HTML using Javascript? For example, in an HTML file, there is paragraph like the following:
I am living in India. India is the very beautiful country.
Now if the user selects India
in the first sentence then there should be an alert 5
and if the user selects India
of second line then there is an alert 6
.
How can I get the index of the word that the user selected?