I am manually calling .click() on a button on a page in my jquery/javascript code.
I need to pass a parameter to click that I can then read on the function that responds to the click event.
is this possible?
In order to pass a value as a parameter through the onClick handler we pass in an arrow function which returns a call to the sayHello function. In our example, that argument is a string: 'James': ... return ( <button onClick={() => sayHello('James')}>Greet</button> ); ...
jQuery trigger() Method The trigger() method triggers the specified event and the default behavior of an event (like form submission) for the selected elements. This method is similar to the triggerHandler() method, except that triggerHandler() does not trigger the default behavior of the event.
You need to invoke .trigger()
. You can pass over any amount of arguments there.
$('element').trigger('click', [arg1, arg2, ...]);
These extra parameters are then passed into the event handler:
$('element').bind('click', function(event, arg1, arg2, ...) {
});
Reference: .trigger()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With