I\'m just starting playing around with d3, and was wondering how you could alternate the colors of a element upon clicking it.
This fiddle changes the color of the
This also worked, albeit in a jankier fashion. . .
var PointColors = ['white', 'magenta']
var sampleSVG = d3.select("#viz")
.append("svg")
.attr("width", 100)
.attr("height", 100);
sampleSVG.append("circle")
.style("stroke", "gray")
.style("fill", "white")
.attr("r", 40)
.attr("cx", 50)
.attr("cy", 50)
.on("click", function(){
PointColors = [PointColors[1], PointColors[0]]
d3.select(this).style("fill", PointColors[0]);});