How to add an event to the input?

Recently I wrote a bot for online games, everything is simple, just a test - calculator - to enter in the field input the new value and click.

Then I tried only
$(rl).val(myNewValue);
did not work, but rather when you click is added to the previous value that was put into this game.
Conclusion: In input, there is some sort of validation. I bypassed it this way:

var input = $('.input-currency').children(0);
var eevent = new Event("input", {bubbles: true, cancelable: true});
input.dispatchEvent(eevent);


Now after 3-4 months, when I returned to finish my bot, it all stopped working. Items in this game remain the same. Sometimes the console gives an error: .dispatchEvent is not a function.
Solved this problem only if I replace $ with document.querySelector.

I need to correctly add\new event to input to solve the problem.

I think the problem is in the events... what do you think ? Please help to deal with the problem.

Thank you in advance.

And how can you add an event using the capabilities of the jQuery library ?
June 14th 19 at 20:28
1 answer
June 14th 19 at 20:30
Solution
Look closely at your code. jQuery-element ≠ DOM element.
// You get the node using jquery and for some reason get it 
// child elements, which in input no
// var input = $('.input-currency').children(0);
var input = $('.input-currency')
var eevent = new Event('input', { bubbles: true, cancelable: true })
// And try to use standard DOM method. 
// input.dispatchEvent(eevent);
// And you need to first get the dom node from the jquery list
input.get(0).dispatchEvent(eevent);


But if you are using jQuery, do this:
$('.input-currency').trigger('input')
Thank You very much!! - terry.Hagenes33 commented on June 14th 19 at 20:33

Find more questions by tags JavaScriptjQuery