Set & Get The Position Of The Text Insertion Point – Caret.js

Category: Javascript | May 10, 2019
Author: abhas9
Views Total: 259
Official Page: Go to website
Last Update: May 10, 2019
License: MIT

Preview:

Set & Get The Position Of The Text Insertion Point – Caret.js

Description:

Caret.js is a vanilla JavaScript library that allows you to set and get the caret position in the editable content.

Supports both textarea and contenteditable elements.

How to use it:

Install & Download.

# NPM
$ npm install vanilla-caret-js --save

Include the minified version of the Caret.js from the dist folder.

<script src="./dist/VanillaCaret.min.js"></script>

Initialize the library on the editable content.

<div contenteditable="true" id="example">

  content here

</div>
var caret = new VanillaCaret(document.getElementById('example'));

Set the caret position.

caret.setPos(3);

Get the current caret position.

caret.getPos();

You Might Be Interested In:


Leave a Reply