I have been facing a strange issue with my script. When I try to execute the following code:
var key="#US"
d3.select(key).style("fill", "red");
it seems like it's not working for me. Interestingly, when I run the same code in the console, it works perfectly fine.
I have tried using functions like document.ready and window.onload, but none of them seem to solve the problem.
After experimenting with different approaches, I came up with this solution:
window.onload = function() {
Object.keys(countries).forEach(function(key){
d3.select(key).style("fill", "red");
});
};
Object.keys(countries).forEach(function(key){
d3.select(key).style("fill", "red");
console.log("t")
});
The strange thing is that it only seems to work when the dev console is active, and even then it only works 1 out of every 4 times. This error has got me puzzled.