JSFiddle - React, Tailwind, and code Playground

by simevidas

HTML

<button id="a" onclick="toggleError(this)">Button A</button>

JavaScript

function toggleError(button) { 
    
    if ( button.className === 'visible' ) {
        
        alert('Error has been hidden!');
        button.className = '';
        
    } else {
        
        alert('Error has been shown!');
        button.className = 'visible';
        
    }
    
}