JSFiddle - React, Tailwind, and code Playground
HTML
<div onclick="doSomething()" id="parent">
<div id="child"></div>
</div>
CSS
#parent {
background-color: blue;
width: 100%;
height: 100px;
}
#child {
background-color: green;
width: 50%;
height: inherit;
}
.myClass {
background-color: red !important;
}
JavaScript
function doSomething() {
event.target.className = ('myClass');
}