JSFiddle - React, Tailwind, and code Playground
HTML
<span id="text1">select this text</span><br>
<span id="text2">Some text</span>
JavaScript
if (!window.James) {
James = {};
}
James.Selector = {};
James.Selector.mouseup = function (e) {
var userSelection;
if (window.getSelection) {
userSelection = window.getSelection();
}
else if (document.selection) {
// should come last; Opera!
userSelection = document.selection.createRange();
}
var selectedText = userSelection;
if (userSelection.text) selectedText = userSelection.text;
if (selectedText != '') {
return selectedText;
}
}
$(document).ready(function () {
$(document).on("mouseup", function (e) {
setTimeout(function(){
alert(James.Selector.mouseup(e));
window.getSelection().removeAllRanges();
},200);
});
});