JSFiddle - React, Tailwind, and code Playground
HTML
<button class="red btn" type="button" id="btn" onclick="changeColor()">Click Me to toggle class</button>
CSS
.btn{
padding:20px 10px;
color:white;
border:none;
}
.red{
background-color:red;
}
.green{
background-color:green;
}
JavaScript
function changeColor() {
document.getElementById("btn").classList.toggle('red');
document.getElementById("btn").classList.toggle('green');
}