Your let clicked = false;
in the beginning of the function will thwart your attempts every time.
If you set it to false at the beginning of the function it is false until you flip it to true. Next time you click, it is set to false before you test it.
I suggest you delegate. Change the class to ID and the class to button
Then delegate from a container
The test is the text on the button - no need for a clicked var now
If you are going to have different languages, use a data-attribute on the button instead of some global boolean
document.getElementById("buttonContainer").addEventListener("click", function(e) {
const tgt = e.target;
if (tgt.classList.contains("button")) {
const text = tgt.textContent;
console.log("Clicked",tgt.id,"to",text)
tgt.textContent = text === "Forget" ? "Connect" : "Forget"
}
});
<div id="buttonContainer">
<button id="buttonOne" class="button">Connect</button>
<button id="buttonTwo" class="button">Connect</button>
<button id="buttonThree" class="button">Connect</button>
</div>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…