function toggle() {
overlays = document.getElementsByClassName("overlay");
if (globalOpacityValue == 0.9){
globalOpacityValue = 0;
}else{
globalOpacityValue = 0.9;
}
console.log("globalOpacityValue: " + globalOpacityValue);
for (overlay in overlays) {
overlays[overlay].style.opacity = globalOpacityValue;
}
console.log("toggle routine done!");
tempStoreOnChangeArtificial();
console.log("tempStoreOnChangeArtificial done!");
}
It seems to me that after the for/in loop, my function ends.
My toggle() never display "toggle routine done!", and obviously it doesn't run the tempStoreOnChangeArtificial();
But it does things in the for/in loop.
why?
overlays[overlay].style.opacity = globalOpacityValue;, there is a chance thatoverlays[overlay]isundefined. Then you are trying to access thestyleproperty ofundefined, which will throw an error.