Accepted answer

The key thing here is that the fade functions return functions themselves. That is, there are two execution scenarios. First, the code of the function itself is executed when the event handlers are assigned (exactly once). Second, the code that actually changes things is executed when the event is triggered (and only then).

You've added your new code in the first execution context. This means that your code is executed exactly once when the handler functions are assigned, not when the events are actually triggered. To achieve what you want, you need to place this code inside the functions that are returned from the fade functions, i.e. below the return function(d, i) line.

Related Query

More Query from same tag