0

How can i make a button in js, which changes its innerText whenever clicked?

19th Jan 2021, 3:01 AM
ARUN GUJJAR
ARUN GUJJAR - avatar
2 Respuestas
+ 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.
19th Jan 2021, 3:11 AM
Ipang
19th Jan 2021, 4:37 AM
AjayGohil