I'm trying to create a button whose change background color (to green) when it is cliked. But when it is cliked againg the button returns to the original background color (from orange).
var btn1 = document.getElementById("btn-1")
if (btn1.style.backgroundColor = "orange") {
btn1.addEventListener("click", function () {
btn1.style.backgroundColor = "green"
})
} else {btn1.addEventListener("click", function () {
btn1.style.backgroundColor = "orange"
})
}
Could you help me? Thx!
I'm trying to create a button whose change background color (to green) when it is cliked. But when it is cliked againg the button returns to the original background color (from orange).