Say I have the following string in Javascript
let str = "This is an example string";
Suppose I highlight the word example (like in Microsoft Word when you want to make a word bold or underlined), how do I get this word's starting and ending index inside of the string str in Javascript? How do I get the values 11 and 17?
So far, everything I tried failed because I could not get these indexes. Working with substrings was of no avail either because you either have to know the string's starting and ending index already or you have to deal with a string in which the selected word is unique.
The above string would be in a contenteditable div.
I should add that Javascript is usually not a strong point of mine, just in case the solution to this should turn out to be all too basic.