<button id="btn1">Click Me!</button>
.clicked { background: green }
// Grab a reference to the button
// "document" is a Web API
const btn = document.getElementById('btn1')

// Add a class to an element
// "classList" is a Web API
const onClick = () => {
  btn.classList.add('clicked')
}

// Associate your custom logic with
// an event on a specific element
// "addEventListener" is another Web API
btn.addEventListener('click', onClick)
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.