I am having a button when I click it becomes active but on another click, I want to remove active CSS
When I click on the button it becomes active by adding an active class to it. Here is what I tried, but what I was trying is when I click on the same buttons the active CSS should be removed, basically want to do toggle
const myDemo = (event) => {
const clickedElem = event.target
const allBtns = document.querySelectorAll('.btn.light')
allBtns.forEach(btn => btn.classList.remove('active'))
clickedElem.classList.add('active')
}
.active {
background: red;
}
<button onclick="myDemo(event)" class="btn light">DOG</button>