allonemoon,
выделить текст, затем кликнуть по красному для снятия выделения.
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
.red {
background-color: #FF0000;
}
</style>
</head>
<body>
<p id="p">Выдели меня: <i>курсив</i> и <b>жирный</b></p>
<script>
function optionStyleText(style, tag) {
let range = window.getSelection().getRangeAt(0);
let selectionContents = range.extractContents();
if (!selectionContents.textContent) return;
let elem = document.createElement(tag);
elem.appendChild(selectionContents);
elem.classList.add(style);
range.insertNode(elem);
}
document.querySelector('#p').addEventListener('mouseup', function() {
optionStyleText('red', 'b')
})
document.querySelector('#p').addEventListener('click', function({ target }) {
if (target = target.closest('b.red')) target.replaceWith(...target.childNodes);
})
</script>
</body>
</html>