JSFiddle - React, Tailwind, and code Playground

by mohammadAdil

HTML

this is text this is anoter text

JavaScript

$("body").on("mouseup", function () {
    var selection = getSelected();
    $(selection).wrapAll("</b>"); 
   
});


 function getSelected() {
    if(window.getSelection) { return window.getSelection(); }
        else if(document.getSelection) { return document.getSelection(); }
                    else {
                            var selection = document.selection && document.selection.createRange();
                            if(selection.text) { return selection.text; }
                return false;
            }
            return false;
        }