Hello,
So I would like to know how I can make a button on which when I first click it it changes the contents of a SPAN and at the time I click it it goes back to the old value.
Hello,
So I would like to know how I can make a button on which when I first click it it changes the contents of a SPAN and at the time I click it it goes back to the old value.
There are several ways you can do this, and usually you do not need to make the button run more than one event.
A simple way is to always keep the next value saved in a variable.
document.getElementById('bt-toggle').addEventListener('click', fnClick);
var proximoValor = 'Teste 2';
function fnClick() {
var span = document.getElementById('span');
var aux = span.innerText;
span.innerText = proximoValor;
proximoValor = aux;
}
<span id="span">Teste 1</span> <br>
<button id="bt-toggle">Toggle</button>