JSFiddle - React, Tailwind, and code Playground

by Medesko

HTML

<a id="button" href="#" class="superman">Run 'superman' class check.</a>

CSS

a {
    margin:20px;
    padding:10px 15px;
    background:#FFD202;
    border-radius:5px;
    color:#222;
    display:inline-block;
    text-decoration:none;
}

JavaScript

// hasClass
function hasClass(elem, className) {
	return new RegExp(' ' + className + ' ').test(' ' + elem.className + ' ');
}
document.getElementById('button').onclick = function() {
    if (hasClass(document.getElementById('button'), 'superman')) {
        this.innerHTML = 'Mission success: \'superman\' class exists.';
    }
}