JSFiddle - React, Tailwind, and code Playground

HTML

<div id="selection">Test of the selection object</div>
<div class="result"></div>

JavaScript

timer = null;

startLoggin = function() {
    timer = setInterval(logThat, 100);
};

logThat = function() {
    $('.result').text(
        document.getSelection().toString().length);
}

stopLoggin = function() {
    clearTimeout(timer);
}

$(document).ready(function() {
    $('#selection').bind('mousedown', startLoggin);
    $('#selection').bind('focu', stopLoggin);
    $('#selection').bind('touchstart', startLoggin);
    //$('#selection').bind('touchend', stopLoggin);

});