How to to check if a button is clicked in JavaScript

#1. How to detect a button click

if(document.getElementById('button').clicked == true)
{
alert("button was clicked");
}

#2. How to check if you clicked something

Here we will have to add an event listener.

// get the element
const element = document.getElementById('profile_title')
// always checking if the element is clicked, if so, do alert('hello')
element.addEventListener("click", () =>…

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store