Can you simulate the keystroke shift
+ enter
in javascript? Basically when a user presses enter
on the keyboard while in a div
where contenteditable=true
I want it to be as if they held down shift
and enter
at the same time. something like the following:
if(e.which == 13)
simulate shift and enter key being pressed simultaneously
I'm doing this because I want the curser to go to a new line as soon as you press enter and I read this can be achieved by pressing shift
+enter
. I have the following code now:
$('element[contenteditable="true"]').keypress(function(event) {
if (event.which == 13){
document.execCommand('innerHTML', false, 'p');
$('element').append('<br>');
return false;
}
});
This code replaces auto generated p
tags in IE
with br
tags but does not go to a new line when the enter
key is pressed. the cursor only moves to a new line when I press another key after the enter
key has been pressed. Any thoughts?