I'm currently doing mouse click event handling for my d3 visualization:
fooCircle.on("click",fooFunction("barParameter"));
My problem is that the function is ran without me having to click on the element. I know this because I put print statements within the function.
Interestingly, when I change the function to not be a function that takes in any parameters, the function behaves has it should, meaning it gets ran when I click on the appropriate element:
fooCircle.on("click",fooFunction);
Someone helped me with the problem. The solution is do:
fooCircle.on("click", function () {fooFunction("barParameter"); });
This way, a function is passed into the on function, as opposed to the result of a function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With