const btn = document.getElementById("btn");
btn.addEventListener("click", function(){
document.style.background-color = "red";
});
<div id ="bck">
<button id="btn">Flip Color</button>
</div>
#bck {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
flex-direction: row;
background-color: #ffa700;
}
#btn{
height: 125px;
width: 300px;
background-color: #008744;
border-radius: 50px;
border: none;
cursor: pointer;
color: white;
font-size: 30px;
font-family: courier;
}
Exotic
February 4, 2022, 1:25pm
2
It should be →
const btn = document.getElementById("btn");
btn.addEventListener("click", function(){
document.body.style.backgroundColor = "red";
});
If you are trying to change the color of the div, just access it with document.getElementById("bck")
and use the style property similar to the above example.
system
Closed
August 6, 2022, 1:26am
3
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.