JSFiddle - React, Tailwind, and code Playground

HTML

<div class="conttext">How hard can it be to achieve this here and now. Will it be difficult or can it be done with great simplicity</div>

<a href="" class="format bold">test</div>

CSS

.highlight {
    color:#888;
}

JavaScript

$(document).ready(function(){
    $('.format').click(function(){
       var highlight = window.getSelection();
       
        var spn = '<span class="highlight">' + highlight + '</span>';
        $('.conttext').content().replace(highlight, spn);
        
    });
});