JSFiddle - React, Tailwind, and code Playground

HTML

<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
<p><strong>Example:</strong> <em>Remove all classes except 'blue' from the matched elements.</em></p>
<pre class="prettyprint linenums"><code class="lang-js">
$('#ex1 p:even').removeClassExcept('blue');
</code></pre>
<div class="example" id="ex1">
  <p class="blue under highlight">Hello</p>
  <p class="blue under highlight">and</p>
  <p class="blue under highlight">then</p>
  <p class="blue under highlight">Goodbye</p>
</div>

<p><strong>Example:</strong> <em>Remove all classes except 'under' and 'highlight' from the matched elements.</em></p>
<pre class="prettyprint linenums"><code class="lang-js">
$('#ex2 p:odd').removeClassExcept('under highlight');
</code></pre>
<div class="example" id="ex2">
  <p class="blue under highlight">Hello</p>
  <p class="blue under highlight">and</p>
  <p class="blue under highlight">then</p>
  <p class="blue under highlight">Goodbye</p>
</div>

CSS

.blue {
  color: blue;
  font-size: '40px';
}
.under {
  text-decoration: underline;
}
.highlight {
  background: yellow;
}

p {
  margin: 0.5em;
  font-size: 1em;
  font-weight: bolder;
}
em {
  color: gray;
}
pre {
  margin: 0 0.5em;
}
.example {
  margin: 1em;
}

JavaScript

$(function () {
	// Remove all classes except those specified
	$('#ex1 p:even').removeClassExcept('blue');  
    $('#ex2 p:odd').removeClassExcept('under blue highlight');
});

// jQuery plugin format
(function ($) {
    $.fn.removeClassExcept = function (options) {
        options = options.replace(/ /g, '|');
        var re = new RegExp('\\b(?:'+options+')\\b\\s*','g');
        this.removeClass(function () { 
            return $(this).attr('class').replace(re, ''); 
        });
        return this;
    };
}(jQuery));