Search code examples
javascriptrangeselectioncontenteditableexeccommand

execCommand doesn't work on selected text


Presumably, I know where's the problem but I have no idea how to fix it. I've got an editable div and <small> elements, clicking on which I want text (that was selected) to be styled. But the problem is it doesn't seem to work at all. Moreover, It wasn't working on further text I was typing until I explicitly added focus on that div. I do think it happens in due to <small> elements, instead of <button>. However, as I've mentioned before, I don't know how to fix it. I've already tried to add ranges in selection, but it didn't make any change. Does anybody know how to fix this nuisance, without changing elements on buttons?


Solution

  • The command doesn't work with elements such as <small>