Jorge• 130
@JorgeIturrieta
Posted
Hi Mahmoud ! Your Javascript code looks good but i think you forgot when an item is active and the user clicks on it, it should close A possible solution to do tath is:
const tabsLi = document.querySelectorAll(".section");
function handleToggle() {
let firstChild = this.firstElementChild;
let lastChild = this.lastElementChild;
// Toggle Action
if (lastChild.classList.contains("show")) {
firstChild.classList.remove("active");
lastChild.classList.remove("show");
} else {
lastChild.classList.add("show");
firstChild.classList.add("active");
}
}
tabsLi.forEach((tab) => tab.addEventListener("click", handleToggle));
This challenge can be done without JavaScript. You can check my solution if you want. FAQ accodion card
I hope I've helped you and keep it up!
Marked as helpful
1