const button = document.getElementById('yourButton');
button.addEventListener('click', (event) => {
// Do something with the event
// https://developer.mozilla.org/en-US/docs/Web/API/Event
})
<!--on html-->
<button>Click Me!</button>
/*js code*/
let btn = document.querySelector('button').addEventListener('click', () => {
console.log('"Ohh!" Button clicked!')
});
/*
HTML
<button id="buttonId" >Click here</button>
*/
document.getElementById('buttonId').addEventListener('click', function(event) {
const button = event.target;
button.innerText = (Number(button.innerText) || 0) + 1;
})