JSFiddle - React, Tailwind, and code Playground

HTML

<textarea id="thearea" style="position: absolute; padding: 0px; width: 200px; height: 3em; outline: medium none;" wrap="off" autocorrect="off" autocapitalize="off" tabindex="0"></textarea>

<br /><br />
<br />
<button onclick="myFunction();">Get Selected Text in Firepad</button>

JavaScript

function myFunction() {
    var e = document.getElementById('thearea');

    //Mozilla and DOM 3.0
    if ('selectionStart' in e) {
        var l = e.selectionEnd - e.selectionStart;

        var start = e.selectionStart,
            end = e.selectionEnd,
            length = l,
            text = e.value.substr(e.selectionStart, l);

        alert(text);
    }
}