I would like to fake an 'enter' keypress event in the browser, without the help of jQuery.
Here's what I tried :
var keyEvent = document.createEvent('KeyboardEvent');
keyEvent.initKeyboardEvent('keyup', true, false, null, 0, false, 0, false, 13, 0);
elem.dispatchEvent(keyEvent);
where elem is one particular element (found with document.querySelector()
)
However the Javascript console tells me initKeyboardEvent()
is not a function.
Now, the documentation does say here that this function is deprecated, but doesn't redirect to the right way to do it nowadays, and I couldn't find any example of how to achieve this by myself either.
Any help on that one?