title: How to change font color of all elements of a class through javascript?
body: <p>I have a button that changes the background image of my web app, and I want to change the color of the font when the button is clicked.</p>
  
  <p>I tried making the element its own variable but that didn't work either.</p>
  
  <pre><code>cafeButton.addEventListener('click', function(){
      bg.style.backgroundImage = "url('img/cafe.jpeg')"; //change text colors
      document.getElementsByClassName('topbutton').style.color = 'blue';
  })
  </code></pre>
  
  <p>When using the above code I get the following error:</p>
  
  <p>Uncaught TypeError: Cannot set property 'color' of undefined
      at HTMLButtonElement.</p>
  
  <p>Here is a codepen of the whole project <a href="https://codepen.io/Games247/pen/XWJqebG" rel="nofollow noreferrer">https://codepen.io/Games247/pen/XWJqebG</a></p>
  
  <p>How do I change the text color of all elements under a class name?</p>