VanillaCaretJS

Set and get Caret position (contenteditable or TextArea) in pure vanilla JavaScript

Hello World. Welcome to Vanilla Caret Js

Setup

npm install vanilla-caret-js
const VanillaCaret = require('vanilla-caret-js');
OR
<script src="https://cdn.jsdelivr.net/npm/vanilla-caret-js@1.1.0/dist/VanillaCaret.min.js"></script>

Example

var caret = new VanillaCaret(document.getElementById('root')); // Initialize
caret.setPos(4); // Set
document.getElementById('currentPosition').value = caret.getPos(); // Get