JSFiddle - React, Tailwind, and code Playground
HTML
<div id="save">What I'm trying to accomplish is allow the user to save text that they've selected (highlighted) on the page with their cursor.</div>
JavaScript
$('#save').click(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)
});