Range: isPointInRange() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2017.

The Range.isPointInRange() method returns a boolean indicating whether the given point is in the Range. It returns true if the point (cursor position) at offset within ReferenceNode is within this range.

Syntax

js
isPointInRange(referenceNode, offset)

Parameters

referenceNode

The Node to compare with the Range.

offset

The offset into Node of the point to compare with the Range.

Return value

A boolean.

Examples

js
range = document.createRange();
range.selectNode(document.getElementsByTagName("div").item(0));
bool = range.isPointInRange(document.getElementsByTagName("p").item(0), 1);

Specifications

Specification
DOM Standard
# dom-range-ispointinrange

Browser compatibility

BCD tables only load in the browser

See also