Changing Text Using Button With JavaScript

Daily post #5 – Hey there, today I’ll be writing about changing some text on the web page when a button is pressed. All of this done using JavaScript of course!

And it does this:

Very cool, right? Just a button changing some text using JS! Nothing great but pretty Awesome šŸ™‚

Explanation:

We first made JS understand that btn is the button which we click and txt is the paragraph tag containing some text which should change when the button is clicked.

We then added an EventListener to btn so we know as soon as it gets clicked. And that triggers the code inside the function.

That code checks if txt is Awesome, make it Not Awesome and vice versa! That’s all šŸ™‚