JSFiddle - React, Tailwind, and code Playground
HTML
<div id="boldB">B</div>
<button id="bld">B</button>
<div id="testBox" contentEditable="true">Some text to play with . . .</div>
CSS
div#testBox {
width:300px;
height:100px;
margin-left:50px;
margin-top:50px;
background-color: yellow;
border:1px solid black;
}
div#boldB {
width:25px;
height:25px;
border:1px solid red;
cursor:pointer;
}
JavaScript
$(document).ready(function(){
$('#boldB').mousedown(function(e) {
e.preventDefault();
document.execCommand('bold', false, null);
alert("clicked the B div");
});
$('#bld').click(function() {
document.execCommand('bold', false, null);
alert("clicked the B button");
});
});