I have this code:
var bt = document.getElementById("bt");
bt.onclick = randomFunc;
Now, how can I pass some parameters to randomFunc
?
I have this code:
var bt = document.getElementById("bt");
bt.onclick = randomFunc;
Now, how can I pass some parameters to randomFunc
?
Create a new function which calls randomFunc
and specify the parameters there.
bt.onclick = function () {
randomFunc(foo, bar, baz);
};
Or, if you can limit support to browsers which support bind
, use that method to create your function:
bt.onclick = randomFunc.bind(this, foo, bar, baz);