I was wondering if there is an acceptable way to force all major browsers to insert paragraph tag instead of the default tag that they insert on pressing enter key when contentEditable is true.
As far as I know IE inserts p automatically. But Google Chrome inserts div tag and Firefox inserts br (WTF?!).
Thanks in advance!
you can use
document.execCommand('formatBlock', false, 'p');
in event likekeypress
orkeydown
, etc. to use paragraphs after enter press. For example:As its build in the browser you can't change that behaviour. You could work around by detecting browser and replacing elements correspondingly. Very ugly, I know.
Also check WhatWG for background: http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2011-May/031577.html
I had this same problem and found the solution (CHROME, MSIE, FIREFOX), follow my code in the link.
https://jsfiddle.net/kzkxo70L/1/