JSFiddle - React, Tailwind, and code Playground

HTML

<div id="container" style="border: 1px solid #333" contentEditable="true">Type text    here</div>

JavaScript

$(document).ready(function() {
    $('#container').mouseup(function() {
        alert(getSelText());
    });
})

function getSelText() {
    var txt = '';
    if (window.getSelection) {
        txt = window.getSelection();
    }
    else if (document.getSelection) {
        txt = document.getSelection();
    }
    else if (document.selection) {
        txt = document.selection.createRange().text;
    }
    else return;
    return txt;
}