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
Make yourself a toggle function and pass it into the click: http://jsfiddle.net/maniator/Bvmgm/6/
var toggleColor = (function(){ var currentColor = "white"; return function(){ currentColor = currentColor == "white" ? "magenta" : "white"; d3.select(this).style("fill", currentColor); } })();