set get caret position - Free Download Set And Get Caret Position Using jQuery - Caret.js

Free Download Set And Get Caret Position Using jQuery – Caret.js

Posted on

This time I will share jQuery Plugin and tutorial about Set And Get Caret Position Using jQuery – Caret.js, hope it will help you in programming stack.

set get caret position - Free Download Set And Get Caret Position Using jQuery - Caret.js
File Size: 4.36 KB
Views Total: 599
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

Caret.js is a tiny jQuery plugin created to set and get caret (text cursor) position in textarea, input, or contenteditable element.

See Also:

How to use it:

1. Load the Caret.js script right before the </body> tag but after jQuery library.

1 <script src="/path/to/cdn/jquery.min.js"></script>
2 <script src="/path/to/jquery.caret.js"></script>

2. Get the caret position.

01 <!-- Textarea -->
02 <textarea id="example">
03   ... Any Content Here ...
04 </textarea>
05  
06 <!-- Or Input Field -->
07 <input id="example" />
08  
09 <!-- Or contenteditable -->
10 <div id="example" contenteditable="true">
11   ... Any Content Here ...
12 </div>
1 $('#example').caret();

3. Set the caret position.

1 $('#example').caret(1);
2 $('#example').caret(-1);
3 ...