For context, I'm trying to make an approximation of how does Google Docs lets users enter comments associated with highlighted text like this:
I'm not trying to implement Google Docs! I just want to let an end-user comment on a specific sentence, paragraph, or heading in a static HTML page. The piece I'm missing is when the user clicks, how do I figure out (using JavaScript) where in the text or DOM that click took place?
Supported Browsers: IE 10+, Edge, Chrome, Firefox, Safari (early 2017), including recent versions of iOS and Android (plus Mac, Windows, Linux).
How to implement Google doc like text editor? is educational, but I'm looking for a way to implement an approximation of only this one feature in a couple of days. What happens on the server, how the position is stored in the database, what happens if the static HTML changes over time, all of that is OUT OF SCOPE for this question. I'm just asking about client-side JavaScript and locating where a user clicked in a document.