I'm using jquery in a web app. I have a page which is listening for keypresses like this:
  document.addEventListener('keyup', function (event) {    
    event.preventDefault();
    var key = event.keyCode;
    console.log("pressed key "+key);
  });
That works in terms of me pressing keys - it outputs the key code to the console.
I now want to simulate a key press with a different function, which i'm doing like this:
  var keycode = 27;
  $(document).trigger(
    jQuery.Event( 'keyup', { keyCode: keycode, which: keycode } )
  );
But, nothing happens - specifically, i don't see the console log from the first function.
Can anyone see my mistake?
EDIT:  it works if I change the first function to use jQuery .on() rather than native js .addEventListener, but i'd still like to understand why.  Is document a different entity to $(document)?
 
     
    