My problem is, the function doesn't find the classname i tried with id but the same error occur. How do i solve this problem or how i do to my function "see" the class, probably is a simple mistake but i don't find the problem
return(
...
<div className="midia-wrapper">
{renderFile()}
</div>
...
<button onClick={changeBackground} className="change-background">
Change Background <i className="fas fa-palette"></i>
</button>
Javascript and css
function changeBackground() {
const randomnumber = Math.floor(Math.random()*10)
const back = document.getElementsByClassName("midia-wrapper");
switch(randomnumber) {
case 1:
back.body.style.backgroundColor = "#ffffff";
break;
case 2:
back.body.style.backgroundColor = "#000000";
break;
case 3:
back.body.style.backgroundColor = "#008bb2";
break;
case 4:
back.body.style.backgroundColor = "#0935B3";
break;
case 5:
back.body.style.backgroundColor = "#B33212";
break;
case 6:
back.body.style.backgroundColor = "#B38612";
break;
default:
back.body.style.backgroundColor = "#ffffff";
}
}
changeBackground()function change a local state and set it to the generated color; then refer to that state to set the background color