Skip to content

Type Editor


Type Editor / @type-editor/dom-util / is-equivalent-position

is-equivalent-position

Functions

FunctionDescription

isEquivalentPosition

Checks if two DOM positions are equivalent.

Scans forward and backward through DOM positions to determine if two positions refer to the same location in the document. This is useful for handling cases like a position after a text node vs. at the end of that text node.

Example

typescript
const textNode = document.createTextNode("Hello");
const parent = textNode.parentNode;
// Position after text node vs. at end of text node
const equivalent = isEquivalentPosition(parent, 1, textNode, 5);