JSFiddle - React, Tailwind, and code Playground
HTML
<div class="wysiwyg">
<textarea>Hello from Stack Overflow!!</textarea>
</div>
JavaScript
function getSelected() {
var t = '';
if (window.getSelection) {
t = window.getSelection();
} else if (document.getSelection) {
t = document.getSelection();
} else if (document.selection) {
t = document.selection.createRange().text;
}
return t.toString();
}
$('.wysiwyg textarea').live('select', function() {
var text = getSelected();
console.log(text);
});