I have a div which is editable and I am trying to format the text using buttons/anchors to trigger JQuery actions. The problem is that If I have a selected text inside the editable div and then if I click on #bold button to make it bold. The text loses focus and nothing happens to it.
HTML
<div class="poster">
    <div class="editor" contenteditable="true" placeholder="What's on your mind?"></div>
    <div class="posterButtons preventCollapse">
        <div class="pull-left">
            <a id="bold">B</a>
            <a id="italic">I</a>
            <a id="underline">U</a>
        </div>
        <div class="pull-right">
            <a class="submitPost">Post</a>
        </div>
    </div>
</div>
JQuery
$('#bold').click(function(){
    document.execCommand('bold', false);
});
 
     
     
    