JSFiddle - React, Tailwind, and code Playground
HTML
<div id="parent">
<div id="child1">bla bla</div>
<div id="child2">fooobar fo foo foo fooooo</div>
</div>
JavaScript
$(function(){
$(document.body).bind('mouseup', function(e){
var selection;
if (window.getSelection) {
selection = window.getSelection();
} else if (document.selection) {
selection = document.selection.createRange();
}
selection.toString() !== '' && alert('"' + selection.toString() + '" was selected at ' + e.pageX + '/' + e.pageY);
});
});