So I have this really basic function with a for loop. It runs fine on modern Chrome and Firefox browsers, but not on a particularly picky Firefox 38 browser. According to the docs this function has been supported since Firefox 13.
function showhide_class(cl) {
var es = document.getElementsByClassName(cl);
for(let e of es) {
e.style.display = (e.style.display == "block") ? "none" : "block";
}
}
The exact error being reported by Firefox is:
SyntaxError: missing ; after for-loop initializer
So, why is this error being reported and do you know of a work around? Thanks so much.
The let
statement is the problem. Use for (var e of es)
instead.
According to MDN, the let
statement did not get support in Firefox until version 44.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With