JSFiddle - React, Tailwind, and code Playground
HTML
<div style="float:left;">
<div id="red" class="color"> </div>
<div id="blue" class="color"> </div>
<div id="green" class="color"> </div>
</div>
<div id="txt">Click on the left side divs to change text color</div>
CSS
.color{
width:50px;
height:50px;
}
#red{
background-color:red;
}
#blue{
background-color:blue;
}
#green{
background-color:green;
}
#txt{
float:right;
font-size:30px;
width:400px;
}
JavaScript
$('.color').on('click',this,function(){
var bgcol = $(this).css('backgroundColor');
$('#txt').css({'color':''+bgcol+''})
});