How to add event listener to attach click event to HTML button in JavaScript

1 Answer

0 votes
<button id="buttonid">Change class name</button>
const btn = document.getElementById("buttonid"); 
 
btn.addEventListener("click", ()=> {
    console.log("JavaScript Event Listener");
})
  
  
  
      
      
/*
run:
  
"JavaScript Event Listener"
  
*/

 



answered Feb 18, 2021 by avibootz
...