const cities = document.querySelectorAll("h2");
const filter = document.querySelector("input");
filter.addEventListener("input", () => {
if (document.querySelector(".active")) {
document.querySelectorAll(".active").forEach((el) => {
el.classList.remove("active");
});
}
cities.forEach((el) => {
console.log();
if (
el.textContent
.toLowerCase()
.split("")
.join(" ")
.includes(filter.value.toLowerCase().split("").join(" "))
) {
el.classList.add("active");
}
});
});
/* ----CONTENT */
.faqs-block-question__content {
line-height: 26px;
margin: 15px 0;
transform-origin: center top;
max-height: 0;
overflow: hidden;
/* ЗАМЕНИЛ height:0 на max-height:0 */
}
.faqs-block-quetions__item.--active .faqs-block-question__content {
/* УБРАЛ heigt: 100% */
}
const textBtns = document.querySelectorAll(".faqs-block-question__title");
textBtns.forEach((el) => {
el.addEventListener("click", (elem) => {
el.parentNode.classList.toggle("--active");
if (
elem.target
.closest(".faqs-block-quetions__item")
.classList.contains("--active")
) {
elem.target
.closest(".faqs-block-quetions__item")
.querySelector(".faqs-block-question__content").style.maxHeight = `${
elem.target
.closest(".faqs-block-quetions__item")
.querySelector(".faqs-block-question__content>h2").offsetHeight
}px`;
} else if (
!elem.target
.closest(".faqs-block-quetions__item")
.classList.contains("--active")
) {
elem.target
.closest(".faqs-block-quetions__item")
.querySelector(".faqs-block-question__content").style.maxHeight = `0px`;
}
});
});