I have a button, which changes its color on hover.
const btn = document.querySelector('.btn');
btn.classList.add('green-background');
.btn {
text-decoration: none;
background: blue;
color: white;
font-size: 20px;
}
.btn:hover {
background: magenta;
cursor: pointer;
}
.green-background {
background: green;
}
<input class="btn" type="submit" value="Click me" />
I would like to add it the green-background class, so that the button is green in default state and on hover as well.
background: magenta;from the hover rule.btn.green-backgroundand when the class gets added, it stays green