0
How can i make a button in js, which changes its innerText whenever clicked?
2 Answers
+ 1
A simple example
<button type="button" onclick="this.innerText = new Date().toString();">Change my caption!</button>
If you want to use event listener, then
- Get a reference to the button (using getElementById, querySelector etc.)
- Add "click" event handler to the button reference, and assign new text for its 'innerText' attribute.
0
Try below code:
https://code.sololearn.com/Wa12a13a15A1/#