My html, css and js are contained in their own files ('index.html', 'javascript.js', 'style.css'). I want to change the background image of a button to represent its state.
Here are the current snippets that I have:
<button id="btn_playPause" type="button" onclick="losAudio_playPause()"></button>
#btn_playPause { background-image: url(../contents/img/losAudio_play.png); height: 35px; width: 35px; }
And finally, JavaScript (point of failure)
function losAudio_playPause() { var losAudio = document.getElementById("losAudio"); if (losAudio.paused) { losAudio.play(); document.getElementById("btn_playPause").style.background-image="url(../contents/img/losAudio_pause.png)"; } else { losAudio.pause(); document.getElementById("btn_playPause").style.background-image="url(../contents/img/losAudio_pause.png)"; } }
I completely lost why the parts of document.getElementByID("btn_playPause").style do not work and cannot find a solution.
source share