ldCaret
Caret Manipulation Library, in Vanilla JS.
Usage
-
download and include ldcaret.js:
you an use a CDN, such as, from jsDelivr:
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/gh/loadingio/[email protected]/dist/ldcaret.min.css"/>
-
call desired API (see below) provided by
ldCaretobject:ldCaret.get();
API
ldCaret provides following API:
-
get() - get selection range in an object with following attributes:
- ns: start container
- os: start offset
- ne: end container
- oe: end offset
-
set(opt) - select based on option object
optwith following attributes:- ns: start container
- os: start offset
- ne: end container ( will use ns when ne is omitted )
- oe: end offset ( will use os when oe is omitted )
-
getContent() - get content from current selection.
-
setContent(content) - replace range of current selection with
content. -
clear() - clear selection.
LICENSE
MIT License.