JSFiddle - React, Tailwind, and code Playground
by Jared Crowe
HTML
<div id="someparent">
Foo
<span id="one">Selection starts anywhere inside here</span>
<span id="two">Selection ends anywhere inside here</span>
<span id="three">Some more text here</span>
Bar
</div>
JavaScript
(function(){
'use strict';
var getSelectionParents=function(){
var selection=document.getSelection();
if(!selection.toString().length)
return false;
else
return {
start:selection.anchorNode.parentNode,
end:selection.focusNode.parentNode
};
}
document.addEventListener('mouseup',function(){
console.log(getSelectionParents());
});
})();