get-selection-range-from-elm

window.getSelection().rangeAt(0) but only if it exists & is within an element

Usage no npm install needed!

<script type="module">
  import getSelectionRangeFromElm from 'https://cdn.skypack.dev/get-selection-range-from-elm';
</script>

README

get-selection-range-from-elm

window.getSelection().rangeAt(0) but only if it exists & is within an element

Installation

Download node at nodejs.org and install it, if you haven't already.

npm install get-selection-range-from-elm --save

Usage

import getSelectionRangeFromElm from 'get-selection-range-from-elm';

const range = getSelectionRangeFromElm(document.querySelector('#foo'));

console.log('range is set if selection is within the element #foo');
console.log(range.startContainer);

Tests

npm install
npm test

Dependencies

None

Dev Dependencies

License

MIT

Generated by package-json-to-readme