Is there a way to create a button that changes color on hover, then reverts back to its original color after it's clicked?
I'm facing an issue where my button initially has a red gradient, then changes color when hovered over, but turns white once it's been clicked. What I actually want is for it to return to red instead of white after being clicked.
I attempted to solve this problem by introducing 'focus'. This seemed to work initially - after the button was clicked, it would revert back to its original color while in focus. However, hovering didn't trigger the color change until the focus was removed from the button.
So far, I haven't been able to find a solution using various pseudo classes or javascript code to maintain the button's red color unless it's being hovered over.
Edit
In response to a suggestion from @webeno, I decided to remove the CSS and try a new approach using the following javascript. Unfortunately, the button still retains its default style. (In this scenario, the colors are blue initially and turn red upon hover.)
<button class = "btn">Go</button>
<script>
.red {background-color: #f00;
}
.blue {background-color: #00f;
}
$(document).ready(function(){
$('.btn').mouseover(function(){
$(this).addClass('red');
}).mouseout(function(){
$(this).addClass('blue');
});
});
</script>