html - Contenteditable paragraph tag on enter -
i wondering if there acceptable way force major browsers insert paragraph tag instead of default tag insert on pressing enter key when contenteditable true.
as far know ie inserts p automatically. google chrome inserts div tag , firefox inserts br (wtf?!).
thanks in advance!
you can use document.execcommand('formatblock', false, 'p');
in event keypress
or keydown
, etc. use paragraphs after enter press. example:
element.addeventlistener('keypress', function(ev){ if(ev.keycode == '13') document.execcommand('formatblock', false, 'p'); }, false);
Comments
Post a Comment