I am attempting to log whenever a county on a d3.js map has been clicked for the first time. The following code updates all elements and I haven't been able to find a way to only assign a true/false to only the element that was clicked.
If I click a county, it turns true and fills it in, if I select that county again, it returns false. If I then select an entirely different county, the value is set to false, and remains false. It never resets back to true.
I feel like I need to be using self
or this
to help define the element-specific boolean but no combination seems to be working.
var noFill = true;
var mousedown = function() {
var self = d3.select(this);
var color = document.getElementById('selcolor').value;
if (noFill) {
console.log(noFill);
self.style("fill", color);
//do some stuff
noFill = false;
} else {
console.log(noFill);
//do some stuff
}
}