Can jQuery simulate a keyup event that will trigger keyup eventlisteners?

Can jQuery simulate a keyup event that will trigger keyup eventlisteners?

Hey everyone. I'm writing a Chrome Extension that will work with a particular website. On that website, there is a function listening for keyup events in a specific input field and I need to trigger that function and give it a specific keyup event. In other word, when you're actually typing in the input field, a function is called after you release each key with the information of the key that was pressed.

Unfortunately, I've had no luck with jQuery's trigger function. Here's a bit of my code:
function simulateKey(iElement) { $( iElement ).focus(); var e = jQuery.Event("keyup"); e.which = 37; e.keyCode = 37; e.charCode = 0; $( iElement ).keyup(function () { console.log("keyup element"); }); $( iElement ).trigger(e); }
When this function is called, "keyup element" is logged to my console, but the website's function doesn't get called. And, if I run this function with an Event Listener Breakpoint set for keyup events, there is no breakpoint.

Let me demonstrate this with simple code on a  JSnippet page that shows what I mean.
When I run the code with my keyup breakpoint set, 65 is logged to the console and set as the value, but the breakpoint never happens.

Then, when I simply click in the input field and press a button, the breakpoint is obviously triggered.



So, can anyone please explain what is going on? Why isn't .trigger working for me? Thanks for any help!