1
I have this div in my html and wanted to make the click on the play button change the text to pause and when clicking again switch to play.
var buttonControl = document.querySelector('#control');
var playNameControl = document.createTextNode('play');
var pauseNameControl = document.createTextNode('pause');
buttonControl.onclick = function control(){
if(buttonControl.value = 'play'){
buttonControl.innerHTML = '';
buttonControl.appendChild(pauseNameControl);
buttonControl.setAttribute('value','pause');
}
else{
buttonControl.innerHTML = '';
buttonControl.appendChild(playNameControl);
buttonControl.setAttribute('value','play');
}
}
<div class="botoes">
<button id="control">play</button>
</div>
It only works for the first click. As it starts with play by clicking it ta changing to pause but clicking again there are no changes more.