Document: caretRangeFromPoint() method
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.
Syntax
caretRangeFromPoint(x, y)
Parameters
Return value
One of the following:
- A
Range. null, if x or y are negative, outside the viewport, or there is no text entry node.
Examples
Visit the Document.caretPositionFromPoint() page to view a live sample of this method.
Specifications
Not part of any specification.