JSFiddle - React, Tailwind, and code Playground
HTML
<button class="button" style="vertical-align:middle" id="buttonclick" onclick="setColor()">
<span>
Enable Control</span></button>
CSS
.button {
display: inline-block;
border-radius: 4px;
background-color: #4f8ff7;
border: none;
color: #FFFFFF;
text-align: center;
font-size: 18px;
padding: 8px;
width: 175px;
transition: all 0.5s;
cursor: pointer;
margin: 13px;
}
.button span {
cursor: pointer;
display: inline-block;
position: relative;
transition: 0.5s;
}
.button span:after {
content: '\00bb';
position: absolute;
opacity: 0;
top: 0;
right: -20px;
transition: 0.5s;
}
.button:hover span {
padding-right: 25px;
}
.button:hover span:after {
opacity: 1;
right: 0;
}
JavaScript
var count = 1;
function setColor() {
var property = document.getElementById('buttonclick');
if (count == 0) {
property.style.backgroundColor = "#4f8ff7"
property.innerHTML = "<span>Enable control</span>"
count = 1;
} else {
property.style.backgroundColor = "#a84237"
property.innerHTML = "<span>Disable control</span>"
count = 0;
}
}