Why does the contentEditable element reject the Enter key?

I am using an application that uses an IE control to display content. I am modifying this content to contain the <div contentEditable="True">Hello World</div> element. This works well, and I can edit the contents of this div, but pressing Enter is rejected by a beep.

When I add a textarea element to this page, the Enter key works, and I can add lines, but not to the contentEditable element.

When I attach an event to this element, I see that pressing the Enter key raises the keyDown event, but not keyPress.

Anyone have an idea what might cause this?

Thanks,
splintor

+4
source share
3 answers

Most HTML elements ignore spaces. Including \ r or \ n in any DIV or similar element is simply ignored.

0
source

I tested it in IE and Firefox, it worked great

0
source

Some, where else do you attach a keydown event for the document.

 document.addEventListener('keydown', handle, false); 

delete it or add keydown event to editable to stop Propagation.

 $('#target').keydown(function(e) { e.stopPropagation(); }); 
0
source

All Articles