JSFiddle - React, Tailwind, and code Playground

HTML

<div contenteditable="true">
Some text. <a href="#" onclick="return false" class="highlight-foo">foo</a> And some other text.
</div>

CSS

.highlight-foo {
    color: red;
    text-decoration: none;
    cursor: normal;
}

JavaScript

var sel = window.getSelection();
var range = document.createRange();
var highlightEl = document.getElementsByClassName("highlight-foo")[0];
range.setStartAfter(highlightEl);
range.collapse(true);
sel.removeAllRanges();
sel.addRange(range);
highlightEl.parentNode.focus();