JSFiddle - React, Tailwind, and code Playground
by khushboo097
HTML
<body>
<div id="c" class="green" onclick="func()"></div>
<style>
#c{
width:100px;
height:100px;
}
.green {
background: green;
}
.red {
background: red;
}
</style>
<script>
var c = document.getElementById('c');
var func = function(){
if(c.classList.contains('green')){
c.classList.remove('green');
c.classList.add('red');
} else if(c.classList.contains('red')) {
c.classList.remove('red');
c.classList.add('green');
}
};
</script>
</body>