I have a pause button that i want the icon to change on click between play and pause icons. The first click works and changes the icon from a play arrow to a pause icon but it will only change once. seemingly the else part of the function doesn't work
The icons used are from materializeCSS framework. I've seen similar questions but couldn't find a solution that worked for me. Not using span and instead using the id of the button in the JS code didn't work for me. it didn't load the icon and just returned plain text "pause" and "play_arrow".
the actual pausing functionality works fine, just a problem with the icons. Sorry if there is a solution posted here already but im new to programming and couldn't find anything myself that matched my problem.
<button class="btn" id="pauseButton" onclick="pause()"><i class="material-icons white-text"><span id="playPause">play_arrow</span></i></button>
var pauseBoolean = 1;
function pause() {
pauseBoolean *= -1;
if (document.getElementById("playPause").innerHTML ="play_arrow") {
document.getElementById("playPause").innerHTML ="pause";
} else {
document.getElementById("playPause").innerHTML ="play_arrow";
}
}
i expected the button to change its content between a pause icon and play icon on each click. Actual result is one change and then it gets stuck. no error messages