I have functiona map d3.js.
I used d3.select(this).style('fill', 'red');to change the color when the user clicks a button svg path.
The color changes, but I want to update the color svg pathto an older one when I click on a new path.
This is the function I used:
.on('click', function(d) {
d3.select(this).style('fill', 'red')
.style('stroke-width', 3);
var year = $(".year-label").text();
var infoYear = 'yr' + year;
var counts = [];
for (i = 1984; i <= 2016; i++){
cnts = 'yr' + i.toString();
counts.push(d.properties[cnts]);
}
console.log(counts);
console.log(counts.length);
$('.text-name').empty();
var nameit = d.properties.city;
$('.text-name').append(nameit);
});
Each path is unique id. So I tried this function without any results:
.on('click', function(d) {
d3.select('._' + d.geoid).this.style('fill', 'red');
I am missing an element, so I am trying to solve it with slight changes in this line. However, this does not work.
This is a picture of this problem:

Thanks in advance for your support!
source
share