<button id="myButton">點擊我</button>
button {
background-color: lightgray;
}
button.active {
background-color: green;
color: white;
}
const button = document.getElementById("myButton");
button.addEventListener("click", () => {
button.classList.toggle("active");
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.