A lightweight (1kb), cross-browser library for DOM selections and ranges. IE9+
$ npm install --save dom-selection
Multiple module systems are included:
dist/dom-selection.js) - This is the
main/default entry. Use as a regular Node module.
dist/dom-selection.min.js) - This is exposed as the
umd:mainentry. It's also minified & can be used in the browser.
dist/dom-selection.es.js) - This is exposed as the
moduleentry. Easier for code-splitting bundlers like Rollup or Webpack.
const domSel = require('dom-selection');
Or you may import it directly into your HTML markup:
<script src="dist/dom-selection.min.js"></script> <script> // the 'DOMSelection' global is now available var range = DOMSelection.getRange(); </script>
[sel] indicates that an existing
Selection object may be provided. By default, the current, active
Selection will be used if available.
Range to a
Selection's rectangular bounds.
Nodes within a
Get the inner HTML content of a
Is there a
Selection to its beginning.
Selection to its endpoint.
Check if the direction of the
Selection was RTL.
Selection within given container
The DOM element to check.
Selection to the container & its children only.
The DOM element that should be the boundary.
Selection to include the full word that the Caret is (partially) within.
Get the full word that the Caret is within.
Selection to include entire words. Can be thought of as "snap to words". No partially-selected words will occur.
MIT © Luke Edwards