I currently have a div
that's used to display and image via CSS.
For example:
HTML
<div id="myDiv" class="play"></div>
CSS
.play{background: url('../img/playIcon_black.png') no-repeat;}
This image appears as it should.
What I'm attempted to do is to change the image by changing the class (via JavaScript).
Example:
CSS
.pause{background: url('../img/pauseIcon_black.png') no-repeat;}
JavaScript
function myFunction() {
myDiv.className = "pause";
}
When I call myFunction()
everything seems to work correctly with one exception. Occasionally the image does not update in the browser.
A few things to note:
- I'm certain the function is being called correctly. If I put a
console.log()
statement within the function, it prints when it should. Additionally, if I inspect the element within the browser, the class is in fact changed to.pause
- The image changes from the "play icon" to blank once the function is called, BUT upon hovering over the
div
the images then appears permanently. - This only seems to happen once the page is initially loaded. Meaning, I can only recreate the issue once upon refresh, then everything works correctly after that.
- I have attempted to clear my cache but nothing seems to have changed.
- (I'm not sure how relevant this is) I'm calling
myFunction()
viaonended
attribute of anaudio
tag.
For example:
<audio onended="myFunction()"></audio>
But I'm not certain if this would affect anything because the function appears to be called correctly.
Any ideas of why this might be happening?