ARTICLE AD BOX
I'm modifying this code (the one at the bottom), but somehow it only works as intended from the second click onward.
const box = document.getElementById('test');
function clickHandler() {
const toggler = document.getElementById('test');
if (toggler.style.backgroundColor === "orange") {
toggler.style.backgroundColor = "green";
}
else {
toggler.style.backgroundColor = "orange";
}
}
test.addEventListener('click', clickHandler);
#test {
background-color:orange;
height:200px;
width:200px;
cursor:pointer;
}
<div id="test">
<p>This box changes from orange to green</p>
</div>
How can I fix this?
