<button id="btn">click me</button>
// event handler function
function clickHandler () {
  alert('You did it!')
}

// Step1: take a reference to the button
//         thatyou want to make clickable.
const btn = document.getElementById('btn')

// Step2: associate your handler function
//        to the event you are interested
//        to, by name.
btn.addEventListener('click', clickHandler)
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.