JSFiddle - React, Tailwind, and code Playground
HTML
<h2 class = "msg"> change button color </h2>
<button class = "blue"> click me </button>
JavaScript
let btn = document.querySelector("button")
let msg = document.querySelector(".msg")
btn.addEventListener("click", () => {
if (btn.classList.contains("blue")) {
btn.classList.add("yellow")
msg.textContent = "button changed to yellow"
} else {
msg.textContent = "button changed to blue"
}
})