<button id="btn1">Click Me!</button>
.clicked { background: green }
/**
 * As a user
 * When I click on a button
 *   Then it should become green
 * And When I click again
 *   It should go back to normal
 */

// 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.toggle('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.