I have this html code:
<div class="feedback-middle">
<button id="btn-1" class="bt1"><p class="b1">What is netflix</p></button>
<div id="btn-1-content" class="aa">ssss</div>
<button id="btn-2" class="bt1"><p class="b1">What is netflix</p></button>
<div id="btn-2-content" class="aa">ssss</div>
<button id="btn-3" class="bt1"><p class="b1">What is netflix</p></button>
<div id="btn-3-content" class="aa">ssss</div>
</div>
and the CSS code:
#btn-1-content,
#btn-2-content,
#btn-3-content {
display: none;
}
.show {
display: block !important;
height: 100px;
background: #303030;
width: 40%;
}
and the js code:
var buttons = document.querySelectorAll(".bt1");
var content = document.querySelectorAll(".aa");
function remove() {
content.forEach((item) => item.classList.remove("show"));
}
buttons.forEach((item) =>
item.addEventListener("click", function (e) {
remove();
const contents = document.querySelector(`#${this.id}-content`);
contents.classList.toggle("show");
})
);
So the problem with this one is that, when i click the button for the first time, i get the div open below, but when i click it for the second time i want the div to get closed, but it doesn't