Skip to content Skip to sidebar Skip to footer

Event Listener Fires On Wrong Target / Function Executes At The Wrong Time

I'm having a problem with an event listener which is firing on the wrong object. To see it, please click on one td with a number below 'Min' Here's the full js code: Here's a fidd

Solution 1:

In the addEventListener you are calling the savethis function instead of passing it in

Change

save.addEventListener('click', savethis(valuenow, id));

to

save.addEventListener('click', savethis);

And find another method to use valueNow and id in the savethis function.

This explains how to pass parameters: https://developer.mozilla.org/en/docs/Web/API/EventTarget.addEventListener


Post a Comment for "Event Listener Fires On Wrong Target / Function Executes At The Wrong Time"