0

I have this code:

var hello = document.getElementById("hello");

hello.onclick = function (e) {
  alert("ok!");
}
#hello {
  padding: 10px;
  background-color: yellow;
}
#hello:active {
  background-color: red;
}
<div id="hello">Hello, A!</div>

You can see that when I click on #hello; that becomes red and js runs the click event, too.

The problem is: As long as the alert box is open, #hello's background still has red effect.

I can solve that; just with a simple setTimeout; but I want to find a standard way (if that isn't).

  • That is the correct way to handle it. – Scott Marcus Mar 24 '20 at 13:20
  • @ScottMarcus You mean there is no other way to solve it? –  Mar 24 '20 at 13:21
  • I can't say definitively that there isn't another way, but that's not what you asked. You asked what the standard way would be. If you read the duplicate link, you'll see exactly what the problem is and why the `setTimeout` solution is the most appropriate. – Scott Marcus Mar 24 '20 at 13:24

0 Answers0