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

Category: Javascript | April 15, 2023
Author:abhas9
Views Total:68 views
Official Page:Go to website
Last Update:April 15, 2023
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();

Changelog:

04/15/2023

  • Fix textarea bug

v1.1.0 (07/16/2022)

  • Update

You Might Be Interested In:


One thought on “Set & Get The Position Of The Text Insertion Point – Caret.js

  1. Janeth

    This looks great! Just one question – Is it compatible with all modern browsers? Any compatibility issues?

    Reply

Leave a Reply