JSFiddle - React, Tailwind, and code Playground

HTML

<nav> <a href="#">FooBar</a>
 <a href="#">FooBar</a>
 <a href="#">FooBar</a>

</nav>

CSS

nav a {
    display: block;
}
nav a.active {
    background: lightgray;
}

JavaScript

$("a").click(function () {
$(this).closest('nav').toggleClass('active');
    //var $this = $(this);
    if ($('nav').hasClass("active")) {
        alert('a');
    } else {
    alert('b');
    }
});