Quantcast
Channel: D3 selectAll change color - Stack Overflow
Viewing all articles
Browse latest Browse all 3

D3 selectAll change color

$
0
0

I am new to D3 and i'm stuck on a case.I have a button that adds circles to my svg.

    d3.select("button#add").on("click", function()    {      svg.append('circle')      .attr('class', 'little')      .attr("cx", Math.random()*280+10)      .attr("cy",Math.random()*280+10)      .attr("r", 12);    });

Afterwards I would like to change the color when you click on a circle. For some reason the code doesn't even start the event.

d3.selectAll(".little").on('click', function()    {        d3.select(this).style("fill", "red");    });

Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images