To extend the answer to @MatuDuke, you can get the position of the selected text like this:
var txt = window.getSelection(), range = txt.getRangeAt(0), boundary = range.getBoundingClientRec(); // Available positions: // boundary.top // boundary.bottom // boundary.left // boundary.right
This will give you pixel values ββrelative to the viewport. However, it does not work in text areas, the problem I'm trying to solve now.
source share