0

I want to add click event to a d3 circle element that is static. I dynamically loaded this d3 code:

     var svgContainer = d3.select("#vis").append("svg")
                                .attr("width", 200)
                                .attr("height", 200);

    //Draw the Circle
      var circle = svgContainer.append("circle")
                    .attr("class","item")
                    .attr("cx", 30)
                    .attr("cy", 30)
                    .attr("r", 20); 

Somewhere in my code, I want to add the click event to circles that contain a class called "item". I am using following code but it does not work

  $('.item').on('click', function(){
     console.log("click added");
  });

I looked at this post as well but it did not help me.

2
  • 3
    Is the click event listener added after the d3 code draws the circles? P.S. d3.js as its own event listening system, you may use it rather than jQuery. Commented Feb 11, 2018 at 19:52
  • Thanks. I was calling it before loading the d3 code. Commented Feb 11, 2018 at 19:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.