I am not very familiar with d3, but this line seems to have too many if :
.style("fill", function(d) { if (d.id == countryCode) { return color(colorCountry(d, d.id));} });
it will be easier if you just do this:
.style("fill", colorCountry);
and change your colorCountry function to
function colorCountry(country) { if (country.id == countryCode) { return '#FF0000'; } else { return color(country.id); } }
or just get rid of the colorCountry function all together and use this
.style("fill", function(d) { return (d.id == countryCode) ? '#FF0000' : color(d.id); });
But why don't you just update your JSON data?
source share