Currently I'm using something like:
$('.myclass').click(function(){
var msg = $(this).attr('id');
alert(msg)
});
And HTML:
< a href="#" class="myclass" id="101">Link</a>
If I need additional parameters how would I read them? Also is the current way I am using the proper way? Originally I was using hidden input fields so it was already a step up. :p
If you want to pass a parameter to the click event handler you need to make use of the arrow function or bind the function. If you pass the argument directly the onClick function would be called automatically even before pressing the button.
Using an inline arrow function. Following the example from above, a very simple way of passing multiple attributes to your handler, is to call the handler from within an inline arrow function. The code added on the onClick line on the <a> element defines an inline arrow function.
To pass multiple parameters to onChange in React:Pass an arrow function to the onChange prop. The arrow function will get called with the event object. Call your handleChange function and pass it the event and the rest of the parameters.
jQuery Events
jQuery .click()
$('.myclass').bind("click", { Param1: "", Param2: 2 }, function(event){
alert(event.data.Param2);
});
you can use bind()
and send additional data to the event handler as event.data
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