JSFiddle - React, Tailwind, and code Playground

HTML

<div id="expander" class="closed">Click Me</div>

CSS

.closed {
    background-color: red;
}

.open {
    background-color: blue;
}

JavaScript

$("#expander.closed").click(function (){
    if ($('#expander').attr('class') === 'closed') {
          $('#expander').attr('class', 'open');
        
          // Add other related functions here
    } else {
        $('#expander').attr('class', 'closed');
        
        // Add other related functions here
    }    
});