On clicking a button I want its color to be inverted.
Below is the html elements under concern:
    <div class='chatbot-container'>
      <div class='chatbot-wrapper' id='chatbot-wrapper' style="display:none;" >
        <iframe
          id="chatbot"
          class="chatbot"
          allow="microphone;"
          src="https://console.dialogflow.com/api-client/demo/embedded/xxx-xxx-xxx"></iframe>
        </iframe>
      </div>
      <button class='chat-btn' type="button" onclick="toggleChatbot()">Q</button>
    </div>
So here is my style sheet:
.chat-btn {
    background: red;
    color: #fff;
    font-size: 32px;
    ....
    <code snipped for brevity>
    ...
}
.chat-btn:hover {
    background: #fff;
    color: red;
}
.chat-btn:active {
    background: #fff;
    color: red;
}
Below is my script:
    <script>
      function toggleChatbot (chatBtn) {
        var x = document.getElementById("chatbot-wrapper");
        if (x.style.display === "none") {
          x.style.display = "block";
          chatBtn.className += ' active';
          console.log(chatBtn.active)
        } else {
          x.style.display = "none";
          chatBtn.className = chatBtn.className.replace(" active", "");
          console.log(chatBtn.active)
        }
      }
    </script>
So if you look at the below snapshot, 'active' is appended to the class as expected.
But the css psuedo class style is not being applied.

 
    