How to check if a button is clicked in JavaScript?

To check if a button is clicked in JavaScript, do this: button.addEventListener('button', () => alert('I am clicked!')).

So if this is your button:

<button id="myButton">I am a button!</button>

Then, when the button is clicked, you can show a popup saying I am clicked! with this JavaScript:

document.getElementById("myButton").addEventListener("click", () => {
  alert("I am clicked!");
});