How to swap HTML button element text using click event JavaScript

1 Answer

0 votes
<input type="button" value="text"  id="btnid" />
const btn = document.getElementById("btnid");
 
btn.addEventListener("click", ()=>{
    if (btn.value === "text") {
        btn.value = "new text";
    } else {
        btn.value= "text";
    }
})
     
     
     
     
/*
run:
     
 
 
*/

 



answered Jun 29, 2021 by avibootz
edited Jun 29, 2021 by avibootz
...