JSFiddle - React, Tailwind, and code Playground

by calder12

HTML

<div style="width:200px;">
    <select class="selectClass red">
    <option value="red">Red</option>
    <option value="blue">Blue</option>
    <option value="green">Green</option>
</select>
<br />
<select class="selectClass red">
    <option value="red">Red</option>
    <option value="blue">Blue</option>
    <option value="green">Green</option>
</select>
</div>

CSS

.red{color:red;}
.blue{color:blue;}
.green{color:green;}
.selectClass{width:300px;}

JavaScript

$("select").on("change",function(){
    
   varCurrent = $(this).attr("class").split(" ");
   varNew = $(this).val();
    $(this).removeClass(varCurrent[1]).addClass(varNew);
});