Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

d3.js on "click" event handling running function without click event

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);
like image 300
tmnt-rafael Avatar asked Nov 20 '12 23:11

tmnt-rafael


1 Answers

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.

like image 178
tmnt-rafael Avatar answered Oct 21 '22 07:10

tmnt-rafael