I made a button and added event listener for click to it. right now I set the following code for JS (button id is next):
next.addEventListener("click", () => {
if (AB.style.backgroundColor === "pink") {
AB.style.backgroundColor = "red";
} else if (AB.style.backgroundColor === "red") {
AB.style.backgroundColor = "orange";
}
});
#AB {
background-color: pink;
}
<div id="AB">Words</div>
<button id="next">Button</button>
Now when I click the button the first time, the color does change from pink to red. However, the second click (namely the else if part) does not do anything. How can I make the color toggle on click?