JSFiddle - React, Tailwind, and code Playground
JavaScript
(function (window, document, $) {
var getSelectedText = function () {
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
}
return text;
};
$(document.body).on("mouseup", function () {
var selectedText = getSelectedText();
if (selectedText.length !== 0) {
alert("You selected: " + selectedText);
}
});
})(window, document, jQuery);