I am making a button that changes from "you" > "wow" > "travel" with every click.
but it makes an error saying "Uncaught TypeError: onoff is not a function at HTMLInputElement.onclick (7.html:15)"
Can you help me solve this problem?
function onoff() {
currentvalue = document.getElementById('onoff').value;
if (currentvalue == "you") {
document.getElementById('onoff').value = "wow";
} else if (currentvalue == "wow";) {
document.getElementById('onoff').value = "travel";
} else {
document.getElementById('onoff').value = "you";
}
}
<input type="button" value="you" id="onoff" onclick="onoff();">
.valuedoesn't capture the text element inside the button element. UseinnerTextinstead..textContent, only use.innerTextif you really need it perfectionkills.com/the-poor-misunderstood-innerText (but in this case,.valueis just fine)valueattribute on abuttonelement. But yes,.textContent(vsinnerText) is good call. In any case, I'm not fan of using a value attribute on abuttonnor of programatically altering buttons as it violates the KISS principle. I'd just creates a button for each action and show/hide as needed.