Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create variables dynamically with a For Loop Javascript

The title plus the following example are self-explanatory of what I don't achieve :-) The idea is to replace something + counter in order to make it work.

      for (var counter = 1; counter <= 6; counter++) {
        var something + counter = $('element' + counter);
        (something + counter).removeAttribute('class');
      }     
like image 308
Bruno Avatar asked Sep 16 '26 17:09

Bruno


1 Answers

You could create an array, but much more simply:

  for (var counter = 1; counter <= 6; counter++) {
    $('element' + counter).removeAttribute('class');
  } 
like image 154
Eran Zimmerman Gonen Avatar answered Sep 18 '26 06:09

Eran Zimmerman Gonen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!