I'm a beginner in javascript and I create a simple project to understand DOM style but faced with a problem. there is a p tag with a red background color and blue color hover effect. I put an onclick event on the p that when user clicks on the p, its background color changes to orange. the problem is when the background color changes with onclick event, the hover effect will be useless then. so is there any problem or this is the routine behavior of javascript?
<html>
<head>
<style>
#p2 {
background-color: red;
}
#p2:hover {
background-color: blue;
}
</style>
</head>
<body>
<p id="p2" onclick="test()"> text </p>
<script>
function test() {
document.getElementById("p2").style.backgroundColor = "orange";
}
</script>
</body>
</html>
I searched in Stackoverflow but unfortunately, these similar questions 1 and 2 didn't help.