AcasCluster is a hard-coded value though. I want to make it a parameter so that I can pass the value through the function.
But how to parameterize this function ? I’m not sure about the syntax . I’m stuck at this part.
Something like below probabily …I’m not sure at this part …I need help here.
param will hold the class values in fact. Could you please correct my syntax ? Also, I’m skeptical as to how to pass the class value to the clicked function also ?
Sorry, but i thought we wanted a closure, so that param could be changed and the listeners would always use the current value. Your example does not currently remove existing listeners, but would have to be called again and again, binding a different set of listeners for each parameter change.
@r51: That will work if the call exists in one place only, but then you wouldn’t need an extra parameter anyway. You are creating a closure with a reference to a variable with ‘top-level’ scope. If you modify that variable’s value later in the code, it will affect the referenced value inside the event listener.
That’s why you need to pass it as I showed in post #4, using an anonymous self-calling function.
As I said, I don’t use jQuery, but I assume that the .click() method adds an event listener for the click event. An event listener is called with a single argument – an Event object (except in Internet Explorer which doesn’t pass any argument; instead relying on a global window.event object).
So if you want to pass an extra parameter you’ll have to wrap the call inside a self-calling anonymous function and create what is known as a closure.
$("#Cluster").click(
(function (param) {
return function (e) {
/* your normal event handler code using 'param' goes here */
};
})("AcasCluster")
);