Non-standard: This feature is not standardized. We do not recommend using non-standard features in production, as they have limited browser support, and may change or be removed. However, they can be a suitable alternative in specific cases where no standard option exists.
The caretRangeFromPoint() method of the Document interface returns a Range object for the document fragment under the specified coordinates.
This method predates the concept of shadow DOM, and will return unpredictable and implementation-specific results in a document that contains ShadowRoot objects.
Use caretPositionFromPoint() instead on supporting browsers because it is a standard method that can return the caret position from within ShadowRoot instances, provided the relevant shadow roots are passed in its options parameter.
caretRangeFromPoint(x, y)xA horizontal position within the current viewport.
yA vertical position within the current viewport.
One of the following:
Range.null, if x or y are negative, outside the viewport, or there is no text entry node.Visit the Document.caretPositionFromPoint() page to view a live sample of this method.
Not part of any specification.