javascript getElementById(myvarnotwork but string yes).className

87 Views Asked by At

A for cicle, that should perform a class change, if I force the value with a string this works, passing the value with a variable not work, why this is happening?

            for (var i = 0; i < A.length; i++) {
              var AA ="FFF"+i;
              document.getElementById(AA).className =  this.off; 
\\                document.getElementById("FFF1").className =  this.off;
                 alert(AA);
              }

the for should replace the number after FFF but it doesn't happen

1

There are 1 best solutions below

0
On

You have the wrong ID when do this var AA ="FFF"+i;. Because for example "FFF" + 0 = "FFF0".