JSFiddle - React, Tailwind, and code Playground

by algorhythm

HTML

<div data-foo="bar" onclick="change(this);" class="Test">Testing</div>
<div data-foo="bar" onclick="change(this);" class="Test">Testing</div>
<input type="button" value="Toggle Class" />

CSS

.Test[data-foo="bar"]{ background-color: Green; }    
.Test[data-foo="baz"]{ background-color: Red; }

JavaScript

jQuery('input[type="button"]').click(function() {
  jQuery('div').toggleClass("Test");
});

jQuery('div').click(function() {
  jQuery(this).attr("data-foo", "baz");
});