JSFiddle - React, Tailwind, and code Playground

by timdown

HTML

<div contenteditable="true">Make a selection in here and then press the button</div>
<div id="save" unselectable="on" class="unselectable"><img
    src="http://jsfiddle.net/img/logo.png" height="50" width="50"
    unselectable="on" /></div>
Selected text: <span id="selectedText"></span>

CSS

.unselectable {
    -khtml-user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

#selectedText {
    font-weight: bold;
}

JavaScript

$('#save').click(function() {
    var selected_text = window.getSelection ? 
        "" + window.getSelection() : document.selection.createRange().text;
    $("#selectedText").text(selected_text);
});