W3cubDocs

/Web APIs

CaretPosition: offsetNode property

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

The offsetNode property of the CaretPosition interface returns a Node containing the found node at the caret's position.

Value

A Node.

Examples

This example logs the offsetNode and offset of the caret position when clicking inside the input field.

<input aria-label="text field" value="Click inside this input field" />
document.querySelector("input").addEventListener("click", (event) => {
  const x = event.clientX;
  const y = event.clientY;

  const caret = document.caretPositionFromPoint?.(x, y);
  if (!caret) {
    log("Not supported");
    return;
  }

  const node = caret.offsetNode;
  const offset = caret.offset;

  log(`offsetNode: ${node}`);
  log(`offset: ${offset}`);
});

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Opera Safari Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet WebView Android WebView on iOS
offsetNode 128 128 20 114 18.4 128 20 85 18.4 28.0 128 No

See also

© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CaretPosition/offsetNode