I have a contentEditable div for implementing a Rich Text Editor as in:
<div contenteditable="true"></div>
I have a drop-down select list to apply a font. I am using execCommand with the fontName option to do so. After selecting some text, when I click on the select button, I lose the selection of the text inside the contentEditable div. Admittedly, I am weak in browser-side Javascript. Is there a quick way around this issue?
$(document).on('click', '#specificFont', function (e) {
...
// tried e.preventDefault() here
...
//Code to get the exact font name
...
execCommand('fontName', null, exactFontName);
});
I tried with mousedown event and with e.preventDefault() too.
I want that the selection is retained when I click on the outside button so that execCommand has it to apply the font.