JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<div><p class="p">some text</p></div>
<p></p>
JavaScript
$.event.props.push('onTextSelect');
$(document).click(function(){
var str=window.getSelection().anchorNode.data;
var str=str.substring(window.getSelection().anchorOffset,window.getSelection().focusOffset);
if(str)
$(window.getSelection().focusNode.parentNode).trigger({type:'onSelectStart',text:str});
});
$('p').on('onSelectStart',function(e){
console.log($(this).attr('class'))
$('p:last').text(e.text);
});