UNPKG

get-selection-range-from-elm

Version:

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

7 lines (4 loc) 247 B
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);