click.html 448 Bytes
Newer Older
Caleb C. Sander's avatar
Caleb C. Sander committed
1
2
3
4
5
6
<html>
  <body>
    <button id='alert-button'>Click me!</button>
    <script>
      // We use the `id` property of the button to access it from JS
      const button = document.getElementById('alert-button')
7
      button.addEventListener('click', () => {
Caleb C. Sander's avatar
Caleb C. Sander committed
8
9
10
        // You could put any other code you wanted here
        // and it would run each time the button is clicked
        alert('Button was clicked')
11
      })
Caleb C. Sander's avatar
Caleb C. Sander committed
12
13
14
    </script>
  </body>
</html>