I am trying to create a button that is set into a content editable. It does set the text I input to bold however, I only want it to set the highlighted text bold instead of the whole text. Any help would be appreciated.
function bold(){
const x = document.getElementById("text");
if(x.style.fontWeight == "bolder"){
x.style.fontWeight = "normal";
}else{
x.style.fontWeight = "bolder";
}
}
<button onclick="bold()"> B </button>
<div id="text" class="editor" contenteditable="true" draggable="true"></div>