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</a>

CSS

.highlight {
    color:#888;
}

JavaScript

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