2

I am trying to pass parameters form 'trigger' event to the triggered event 'click' in Jquery. Jquery documentation says that you can pass external parameters in an array 'extraParameters'. However, I don't know who to receive those parameters in the triggered event. 'click' in my case.

The code that I am using to pass parameters in the trigger event is like the following:

$("#add_docs").trigger("click", [request_id]);

The code that I am using to get the parameters form the 'trigger' event in my 'click' event is like the following:

$("#add_docs").click(params, function () { console.log(params[0]) });

There is wrong with the way that I am trying to get the params. I need a little help here please.

1 Answer 1

7

Extra arguments are passed sequantially to the callback, beginning from the second argument (the first is the event object).

$('button').on('click', function(evt, param1, param2) {
    alert(param1+'-'+param2); //"bar-foo"
})

These are then passed as an array via the second param of trigger().

$('button').trigger('click', ['bar', 'foo']);
Sign up to request clarification or add additional context in comments.

2 Comments

I see, what a stupid mistake.. I completely missed this point
I will mark you answer as the answer to this question :) Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.