The problem with focus
event on a div
is that it can't fire because it thinks a div
should not be editable. Editable contents in the DOM are marked with tabindex
in the background, so in order for your div to receive the onfocus
event, you need to explicitly declare the div
's tabindex
property.
HTML:
<div style=" border:solid 1px #D31444" contenteditable="true" tabindex="1" onfocus="document.execCommand('selectAll',false,null)" >12 some text...</div>
That should work with onfocus
.