JSFiddle - React, Tailwind, and code Playground

by jfriend00

HTML

<div id="test" class="time">Watch the color of this text change because the class changes when you click the button</div>
<br><button onclick="run()">Click Here</button>

CSS

.time {color: blue;}
.test {color: red;}

JavaScript

function run() {
    // if the class name is not empty, then change it
    if (document.getElementById("test").className) {
        document.getElementById("test").className = "test";
        alert("got message");
    }
}