JSFiddle - React, Tailwind, and code Playground
HTML
<p>
Hello my name is jimmy john. I hate sandwiches.
<p>
JavaScript
function getSelectedText() {
t = (document.all) ? document.selection.createRange().text : document.getSelection();
return t;
}
$('body').mouseup(function(){
var selection = getSelectedText();
var selection_text = selection.toString();
console.log(selection);
console.log(selection_text);
// How do I add a span around the selected text?
});