Document: caretRangeFromPoint() method

فهرست فصل‌ها دانلود آرشیوناشر

MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونه‌کد

{{APIRef("DOM")}}{{Non-standard_header}}

The **caretRangeFromPoint()** method of the {{domxref("Document")}} interface returns a {{domxref("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 {{domxref("ShadowRoot")}} objects.

Use {{domxref("Document/caretPositionFromPoint", "caretPositionFromPoint()")}} instead on supporting browsers because it is a standard method that can return the caret position from within {{domxref("ShadowRoot")}} instances, provided the relevant shadow roots are passed in its options parameter.

Syntax

js-nolint
caretRangeFromPoint(x, y)

Parameters

  • x
  • : A horizontal position within the current viewport.
  • y
  • : A vertical position within the current viewport.

Return value

One of the following:

  • A {{domxref("Range")}}.
  • null, if _x_ or _y_ are negative, outside the viewport, or there is no text entry node.

Examples

Visit the {{domxref("Document/caretPositionFromPoint#Examples", "Document.caretPositionFromPoint()")}} page to view a live sample of this method.

Specifications

Not part of any specification.

Browser compatibility

{{Compat}}

See also

  • {{domxref("Document.caretPositionFromPoint()")}}