Both the button and the div have the same \'onclick\' code, yet the execCommand only seems to work on the button. Is there any way I can make it work when pressing the div?<
You need to prevent the mousedown event on your div because it steals the focus:
mousedown
Updated fiddle