Sorry if this is a basic question, but how can I keep a button in the :active state after clicking?
In case it's relevant, I have a sidebar with 5 buttons. Four of them trigger the appearance of one div while hiding the others, and the fifth button functions as an accordion.
HTML
<content class="menu">
<button onclick="myFunction1();">Home</button>
<br>
<button onclick="myFunction2();">About</button>
<br>
<button class="accordion">Work</button>
<content class="panel">
<button id="submenu" class="Work1" onclick="myFunction3();">Work1</button>
</content>
<button onclick="myFunction4();">Contacts</button>
</content>
CSS
content.panel {
display: none;
}
JavaScript
function myFunction1() {
document.getElementById("Home").style.display = "block";
document.getElementById("About").style.display = "none";
document.getElementById("Work1").style.display = "none";
document.getElementById("Contacts").style.display = "none";
}
function myFunction2() {
document.getElementById("Home").style.display = "none";
document.getElementById("About").style.display = "block";
document.getElementById("Work1").style.display = "none";
document.getElementById("Contacts").style.display = "none";
}
function myFunction3() {
document.getElementById("Home").style.display = "none";
document.getElementById("About").style.display = "none";
document.getElementById("Work1").style.display = "block";
document.getElementById("Contacts").style.display = "none";
}
function myFunction4() {
document.getElementById("Home").style.display = "none";
document.getElementById("About").style.display = "none";
document.getElementById("Work1").style.display = "none";
document.getElementById("Contacts").style.display = "block";
}
var acc = document.getElementsByClassName("accordion");
var i;
for (i = 0; i < acc.length; i++) {
acc[i].onclick = function(){
/* Toggle between adding and removing the "active" class,
to highlight the button that controls the panel */
this.classList.toggle("active");
/* Toggle between hiding and showing the active panel */
var panel = this.nextElementSibling;
if (panel.style.display === "block") {
panel.style.display = "none";
} else {
panel.style.display = "block";
}
}
}