JSFiddle - React, Tailwind, and code Playground

by mohammadAdil

HTML

<textarea id="txtarea2" cols="50" rows="10">This is Some Text</textarea>

JavaScript

function getSelText(){
    var text = "";
    if(window.getSelection){
        text = window.getSelection();
    }
    else if(document.getSelection){
        text = document.getSelection();
    }
    else if(document.selection){
        text = document.selection.createRange().text;
    }
    console.log(text);
    return text;
    
} 

$(function(){
  $('#txtarea2').on('mouseup',function(){
   getSelText();
 });
})