JSFiddle - React, Tailwind, and code Playground
HTML
<p>sdssddsdssd</p>
JavaScript
document.getElementsByTagName('p')[0].onmouseup = function() {
if (typeof window.getSelection === 'function') {
//code
var selObj = window.getSelection();
alert(selObj);
var selRange = selObj.getRangeAt(0);
}
else if (document.selection) {
alert(document.selection.createRange().htmlText) //IE6 7 8
}
}