I'm working on a project, and i have to trigger React onKeyPress
event with Javascript, I was able to trigger the event in Mozilla with the following code:
var evt = document.createEvent("KeyboardEvent");
evt.initKeyEvent("keypress", true, true, window, false, false, false, false, 13, 13)
elment.dispatch(evt);
but failed to do in Chrome as Chrome doesn't support initKeyEvent
, is there any workaround?
P.S: I want to press the enter key in the textarea.