Reputation: 2135
I've seen examples where to add an event listener, both a KeyboardEvent is created/dispatched and an addEventListener is called. Is there a reason to do both (maybe older IE versions)? Or is simply addEventListener
enough to support all browsers + >= IE11.
const keyboard = new KeyboardEvent('keyup', { view: window, bubbles: true, cancelable: true });
document.addEventListener('keyup', _closureMethod, false);
document.dispatchEvent(keyboard);
Upvotes: 0
Views: 443
Reputation: 11313
You are describing two different things:
addEventListener
on keyup
, you wait for a keyup
event to be triggered by the press of a keyboard button.KeyboardEvent
and dispatching it simulates a keyup
event. You don't need an event listener for that, because it's an artificial event.Upvotes: 1