JSFiddle - React, Tailwind, and code Playground
by pradeep
HTML
<div id='selectable'>
select some of this text, the result will show up below
</div>
<div id='result'>
Text Selected? <span class='resize-text'>false</span><br />
Selection: <span class='selection'></span>
</div>
CSS
div {
margin-top: 10px;
padding: 10px;
border: 2px solid black;
width: 200px;
}
JavaScript
$('#selectable').on("mouseup", function () {
$('.selection').wrap("<span>"+window.getSelection().toString()+"</span>");
$('.resize-text').text();
if(window.getSelection().toString() != ""){
alert("true");
}
});