I am using JQuery trigger but am not sure what the correct syntax is to pass parameters in my situation. Here is where I am making the call :
$('#'+controlName).trigger(event);
Here is where I am doing the event binding :
$(window).on('onPartialRendered', onPartialRendered);
And here is my event handler :
var onPartialRendered = function () { ..... };
Everything works fine until I try to pass parameters. What would be the correct way to do it as per my example?
The trigger() method is a method in jQuery which is used to trigger a specified event handler on selected element. Syntax: $(selector).trigger(event, param1, param2) Note: Extra parameters can be passed in trigger() method. Example 1: This method triggered two methods to increase the value of method.
Answer: Use the jQuery click() Method You can use the click() method to trigger a click on a link programmatically using jQuery.
If you want to trigger click event without clicking a button manually, then you should use the click() method in Javascript. Example : click button on page load dynamically. For that we will create a button with an id my-btn . So that, we can select the button using the getElementById() method.
First parameter is always string with event name and next parameters are additional data:
.trigger('foo', [1, 2]); .on('foo', function(event, one, two) { ... });
Special thanks for Rocket Hazmat
var controller = { listen: function (event, json, string) {} }; $('body').trigger('this_works', [{data: [1, 2, 3]}, 'something']); $('body').on('this_works', function (event, json, string) { controller.listen(event, json, string); });
Please do not use this way. There is many article about this problem in network. This take much time and generate unnecessary traffic in network. Please use this way:
var template = $('#templates #example_template').detach(); var clone = template.clone(); clone.find('.some_field').val('new_data'); clone.attr('id', null); $('table tbody').append(clone);
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