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.
I tried making the element its own variable but that didn't work either.
cafeButton.addEventListener('click', function(){
bg.style.backgroundImage = "url('img/cafe.jpeg')"; //change text colors
document.getElementsByClassName('topbutton').style.color = 'blue';
})
When using the above code I get the following error:
Uncaught TypeError: Cannot set property 'color' of undefined at HTMLButtonElement.
Here is a codepen of the whole project https://codepen.io/Games247/pen/XWJqebG
How do I change the text color of all elements under a class name?