I have the following code, that simply creates a div, which when hovered over, should change its background color to red:
setTimeout(function() {
document.getElementById('example-id').className = 'example-class';
}, 1);
.example-class:hover {
background: red;
}
<body>
<div id="example-id">example text</div>
</body>
This code seems to work in all of the browsers that I've tested it in, with the exception of google chrome. Specifically, I've tested it with the following operating systems and browsers:
- Windows 10 Home: Version 1703
- Chrome: 62.0.3202.94
- Firefox: 57.0
- Firefox ESR: 52.5.0
- Edge: 40.15063.674.0
- IE11: 11.726.15063.0
- OS X El Capitan: Version 10.11.6
- Safari: Version 11.0.1
However, if I remove the use of the setTimeout function, so that the class is added to the div immediately, then the code works as expected in all browsers.
So why is this happening? Is this a bug in google chrome, or an ambiguity in some spec somewhere, or is it something else?