https://github.com/abhas9/vanilla-caret-js
Set and get Caret position (contenteditable or TextArea) using Vanilla JavaScript
https://github.com/abhas9/vanilla-caret-js
caret caretjs contenteditable dom javascript textarea
Last synced: about 1 year ago
JSON representation
Set and get Caret position (contenteditable or TextArea) using Vanilla JavaScript
- Host: GitHub
- URL: https://github.com/abhas9/vanilla-caret-js
- Owner: abhas9
- License: mit
- Created: 2019-04-28T08:14:29.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-05-03T23:18:05.000Z (about 3 years ago)
- Last Synced: 2025-03-14T01:35:29.798Z (about 1 year ago)
- Topics: caret, caretjs, contenteditable, dom, javascript, textarea
- Language: JavaScript
- Homepage: https://abhas9.github.io/vanilla-caret-js/
- Size: 1.03 MB
- Stars: 38
- Watchers: 4
- Forks: 2
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Set and get Caret position (contenteditable or TextArea) using Vanilla JavaScript
====================
[![NPM version][npm-version-image]][npm-url]
[![NPM size][npm-size-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Donate][donate-image]][paypal-link]
[![MIT License][license-image]][license-url]
# Demo
[](http://abhas9.github.io/vanilla-caret-js)
# Setup
```shell
$ npm i vanilla-caret-js
const VanillaCaret = require('vanilla-caret-js');
```
OR
```javascript
```
# Example Usage
```javascript
var caret = new VanillaCaret(document.getElementById('root')); // Initialize
caret.setPos(4); // Set
document.getElementById('currentPosition').value = caret.getPos(); // Get
```
# 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`):
```shell
$ npm install
```
## Available tasks
### Build and test
```shell
$ node make # or also `$ npm run default`
```
### Convert the ES6 code into valid ES5 combining all the modules into one single file
```shell
$ node make build # or also `$ npm run build`
```
### Start a nodejs static server
```shell
$ node make serve # or also `$ npm run serve`
```
[license-url]: LICENSE
[license-image]: http://img.shields.io/badge/license-MIT-000000.svg?style=flat-square
[paypal-link]:https://www.paypal.me/abhas9
[donate-image]:https://img.shields.io/badge/donate-%E2%9D%A4-brightgreen.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/vanilla-caret-js
[npm-version-image]: http://img.shields.io/npm/v/vanilla-caret-js.svg?style=flat-square
[npm-size-image]: https://img.shields.io/bundlephobia/min/vanilla-caret-js.svg?style=flat-square
[travis-url]:https://travis-ci.org/abhas9/vanilla-caret-js
[travis-image]: https://api.travis-ci.org/abhas9/vanilla-caret-js.svg?branch=master&style=flat-square