How can I change the button color after clicking it? I have a single button that will change to red on the first click, yellow on the second click, green on the third click, and then become disabled after three clicks.
function updateBtnColor() {
$('.btn-api').click(function() {
var $this = $(this),
$clickCounts = 1;
if ($clickCounts === 1) {
$this.addClass('bg-act-red');
$clickCounts += 1;
} else if ($clickCounts == 2) {
$this.addClass('bg-act-yellow');
$clickCounts += 1;
} else if ($clickCounts == 3) {
$this.addClass('bg-act-green');
$clickCounts += 1;
}
});
}
.btn-api {
display: block;
margin: 0 auto;
width: 100px;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #ddd;
border-radius: 50px;
padding: 5px;
cursor: pointer;
text-align: center;
font-size: 12px;
}
.bg-act-red {
background-color: #c5363a;
color: white;
}
.bg-act-yellow {
background-color: yellow;
color: white;
}
.bg-act-green {
background-color: green;
color: white;
}
<span class="btn-api"> Change to In Progress </span>