How To Pass Parameters To A Function Being Passed As An Argument Of AddEventListener Or Being Assigned To An Event Handler?
What is the correct and professional way to add parameters to a function being passed to addEventListener() or or being directly assigned to an event handlers as in el.onclick = do
Solution 1:
You can use an anonymous function when you need to pass parameters to another, like this:
el.addEventListener("click", function() { doSomething(param); }, false);
Whereas if it didn't need parameters, it would just be:
el.addEventListener("click", doSomething, false);
Post a Comment for "How To Pass Parameters To A Function Being Passed As An Argument Of AddEventListener Or Being Assigned To An Event Handler?"