Set and get Caret position (contenteditable or TextArea) using Vanilla JavaScript
Demo
Setup
$ npm i vanilla-caret-js
const VanillaCaret = require('vanilla-caret-js');
OR
<script src="https://cdn.jsdelivr.net/npm/vanilla-caret-js@1.0.1/dist/VanillaCaret.min.js"></script>
Example Usage
var caret = new VanillaCaret(document.getElementById('root'));
caret.setPos(4);
document.getElementById('currentPosition').value = caret.getPos();
Development
Once you've downloaded the files in this repo please run the following command in your terminal from the project folder (it may require sudo
):
$ npm install
Available tasks
Build and test
$ node make
Convert the ES6 code into valid ES5 combining all the modules into one single file
$ node make build
Start a nodejs static server
$ node make serve