JSFiddle - React, Tailwind, and code Playground
HTML
<button id="button">Pressez moi</button>
CSS
button {
padding: 1em;
width: 300px;
background: #eee;
border: 1px solid #888;
}
JavaScript
const button = document.getElementById("button");
// On ajoute un évenement sur le bouton qui se déclanchera
// Quand le click sera initié
button.onmousedown = () => {
button.style.background = "lightgreen"
button.textContent = "Pressé !"
}
// Quand le click est relaché on remettra le bouton a son état initial
// Ici nous ajouterons l'évenement sur la page entière au cas ou le click
// serais relaché ailleurs que sur le bouton même.
document.onmouseup = () => {
button.style.background = ""
button.textContent = "Pressez moi !"
}