I have read a lot of posts here but I can't find the solution.. Any ideas why hover color doesn't work on second click? (example with snippet or jsfiddle please) Thanks!!!
function toggleButton() {
var button = document.getElementById('toggle').style.backgroundColor;
var color = '';
if (button !== 'pink') {
color = 'pink';
document.getElementById('toggle').style.backgroundColor = color;
document.getElementById('toggle').style.color = "#222";
} else if (button === 'pink') {
color = '#2c475c';
document.getElementById('toggle').style.backgroundColor = color;
document.getElementById('toggle').style.color = "#fff";
}
}
#toggle {
padding: 20px 45px;
background: green;
color: #fff;
border-radius:5px;
font-weight:600;
}
#toggle:hover {
background: aqua;
}
<button id="toggle" onclick="toggleButton();">TOGGLE</button >