I have a contenteditable div and would like to trigger an 'enter' when certain keys (like D) are pressed. Below code doesn't work...
$('#div_edit').keydown(function(e) {
if(e.keyCode == 68) {
var k = jQuery.Event('keypress', { which: 13 });
$('#div_edit').trigger(k);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="div_edit" contenteditable="true"></div>
I'm only concerned about Chrome.
EDIT: I would like to add that everytime the D key is pushed, it creates a new element 'div' inside the contenteditable where the user can continue typing in the new div/new line. Example:
<div id="div_edit" contenteditable="true">
<div>The start of the sentence</div>
<div>user hit D so continue typing here</div>
</div>
EDIT: I guess my main question is, is there no way to trigger an ENTER in a contenteditable element???