caret-xy
v2.0.3
Published
Viewport-based (fixed) caret position for HTML input and textarea elements
Downloads
1,430
Readme
Viewport-based (fixed) caret position for HTML input and textarea elements. This project is based on textarea-caret-position.
npm i caret-xyor
yarn add caret-xyAPI
caretXY(element, position)elementinput or textarea DOM element.positionis an integer indicating the location of the caret (defaults toelement.selectionEnd).
Sample
import caretXY from 'caret-xy'
const input = document.querySelector('input')
caretXY(input)Known Issue
- Does not work properly for
<input type="email"/>,<input type="password"/>(element.selectionEndalways returnsnull).
