JSFiddle - React, Tailwind, and code Playground
HTML
<div id="save">Check</div>
<p>What I'm trying to accomplish is allow the user to save text that they've selected (highlighted) on the page with their cursor.</p>
JavaScript
$('#save').mousedown(function(){
var selected_text = "";
if (window.getSelection) {
selected_text = window.getSelection();
} else if (document.getSelection) {
selected_text = document.getSelection();
} else if (document.selection) {
selected_text = document.selection.createRange().text;
}
alert(selected_text)
});