title: Javascript setAttribute from Array
body: <p>I have a css file with classes and an array with these classes stored as such:</p>
  
  <pre><code>myArray[0] = myClass1
  myArray[1] = myClass2
  // etc...
  </code></pre>
  
  <p>I have tried several methods now and searched for an answer on how to <code>setAttribute()</code> class to the classes stored in my array. Basically what I need to do is:</p>
  
  <pre><code>myElement.setAttribute("class",myClass1);
  </code></pre>
  
  <p>But I cannot figure out how. </p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Maybe I should've been more clear, but anything except typing out the classname inside "" doesn't work. Basicly what I have is an array and a variable with a random classname from the array. I want to set the classname using setAttribute() to that variable. </p>