100-project-100-days-website/100_projects/12-create-tabs/main.js
2023-03-05 17:26:14 +03:00
Ask

17 lines
557 B
JavaScript

{889b83e6e025e23c922c634b82ace31f0bb0eb4b true 557 main.js 0xc001ea93b0}

let tabs = document.querySelectorAll(".tabs li");
let tabsArray = Array.from(tabs);
let divs = document.querySelectorAll(".content > div");
let divsArray = Array.from(divs);
tabsArray.forEach((ele) => {
ele.addEventListener("click", function (e) {
tabsArray.forEach((ele) => {
ele.classList.remove("active");
});
e.currentTarget.classList.add("active");
divsArray.forEach((div) => {
div.style.display = "none";
});
document.querySelector(e.currentTarget.dataset.cont).style.display = "block";
});
});