I have a div (acting as a button) which has certain CSS that activates when hovered on:
#btn{
width: 80%;
height: 125px;
border: 1px solid #9676E8;
border-radius: 10px;
transition: background-color 0.25s ease;
background-color: #B299F2;
color: white;
}
#btn:hover{
background-color: #9676E8;
}
Note: #9676E8 is a darker shade of #B299F2, both blue.
This button has a toggle function, where the desired effect is that clicking it will toggle its background to become red instead of blue. The relevant JavaScript is here:
var btn = document.getElementById("btn");
btn.addEventListener("click",function(){
if(!toggle){
toggle = true;
btn.style.border = "1px solid #FF0000";
btn.style.backgroundColor = "#AA3030";
} else {
toggle = false;
btn.style.border = "1px solid #9676E8";
btn.style.backgroundColor = "#B299F2";
}
});
Note: #AA3030 and #FF0000 are shades of red.
My problem is that after clicking the button the first time, the button turns red (as desired). However, when clicking it so it changes back to blue, there is no more hover effect afterward. Hovering over it doesn't do anything but clicking it still works.
I do not need the button to have a hover effect while it is red, but I want to retain the hover effect while it is blue. Is there any way of doing so?