+ 4

How would we change the text on the press of a button in HTML.

I am making something and I want it to swap between two different sets of text. So like, it may say “Hello” when you push one button, and when you press the other, it says “goodbye”. But I want it to be interchangeable and not get stuck on one of the two. So you can swap back and forth. Any help is appreciated, thanks.

8th Mar 2018, 10:26 PM
Jax
Jax - avatar
5 Respostas
+ 3
well we recommend you try and show where you fail, then you get help. -------------Anyways use javascript or Jquery-----@@@ e. g {Html} <button class="btn btn-primary" id="sayhello" onclick="toggleSayhello()">Hello</button> {Javascript} function toggleSayhello(){ var x = document.getElementById("sayhello"); if(x.value =="Hello"){ x.innerHTML = "Hi"; }Else{ x.innerHTML="Hello"; } } something like that.... I didn't test though
8th Mar 2018, 11:00 PM
Strange
Strange - avatar
+ 2
I didn’t even know where to start, that’s why I’m asking you guys.
8th Mar 2018, 11:05 PM
Jax
Jax - avatar
+ 2
why @Goner
9th Mar 2018, 11:16 AM
Strange
Strange - avatar
+ 1
@Goner Sorry it took so buddy. I will be sure to decline them in just a few seconds. 😉
9th Mar 2018, 2:38 PM
Jax
Jax - avatar