Search code examples
buttonaddtextchangedlistener

how to make a function to change the text back and forward


I just want to change the button text

<button id="reset">Reset</button>
$("#reset').on("click", function () {
this.textContent  = "Loading....";
setTimeOut("this.textContent = " Reset", 2000)
}

after I clicked it will change the text to Loading and in few second it turn back to Reset. I tried to add text


Solution

  • You don't need jQuery.

    Just this:

    <button id="reset" onclick="this.textContent = 'Loading...'; setTimeout( e => this.textContent = 'Reset', 2000 );">Reset</button>