Все сервисы Хабра
Сообщество IT-специалистов
Ответы на любые вопросы об IT
Профессиональное развитие в IT
Закрыть
Задать вопрос
Вячеслав Мухин
web-разработчик
0
вклад
2
вопроса
1
ответ
0%
решений
Комментарии
Информация
Ответы
Вопросы
Комментарии
Подписки
Нравится
Как это лучше запрограммировать?
Вячеслав Мухин
@slavaweb
Автор вопроса
все это конечно круто но я имел в виду используя этот код который есть и те методы которые в нем
Написано
более трёх лет назад
Как это лучше запрограммировать?
Вячеслав Мухин
@slavaweb
Автор вопроса
спасибо, но то что вы написали я не пойму по ссылки в редакторе js ничего не написано
Написано
более трёх лет назад
Как это лучше запрограммировать?
Вячеслав Мухин
@slavaweb
Автор вопроса
var toggle = document.querySelectorAll(".faq__accordion-toggle");
var answer = document.querySelectorAll(".faq__accordion-answer");
toggle[0].addEventListener("click", function (event){
event.preventDefault();
console.log("Клик по ссылки");
if (answer[0].classList.contains("faq__item-answer-show")) {
answer[0].classList.remove("faq__item-answer-show");
}
else {
answer[0].classList.add("faq__item-answer-show");
answer[1].classList.remove("faq__item-answer-show");
answer[2].classList.remove("faq__item-answer-show");
answer[3].classList.remove("faq__item-answer-show");
answer[4].classList.remove("faq__item-answer-show");
answer[5].classList.remove("faq__item-answer-show");
answer[6].classList.remove("faq__item-answer-show");
answer[7].classList.remove("faq__item-answer-show");
answer[8].classList.remove("faq__item-answer-show");
answer[9].classList.remove("faq__item-answer-show");
answer[10].classList.remove("faq__item-answer-show");
answer[11].classList.remove("faq__item-answer-show");
}
});
toggle[1].addEventListener("click", function (event){
event.preventDefault();
console.log("Клик по ссылки");
if (answer[1].classList.contains("faq__item-answer-show")) {
answer[1].classList.remove("faq__item-answer-show");
}
else {
answer[0].classList.remove("faq__item-answer-show");
answer[1].classList.add("faq__item-answer-show");
answer[2].classList.remove("faq__item-answer-show");
answer[3].classList.remove("faq__item-answer-show");
answer[4].classList.remove("faq__item-answer-show");
answer[5].classList.remove("faq__item-answer-show");
answer[6].classList.remove("faq__item-answer-show");
answer[7].classList.remove("faq__item-answer-show");
answer[8].classList.remove("faq__item-answer-show");
answer[9].classList.remove("faq__item-answer-show");
answer[10].classList.remove("faq__item-answer-show");
answer[11].classList.remove("faq__item-answer-show");
}
});
toggle[2].addEventListener("click", function (event){
event.preventDefault();
console.log("Клик по ссылки");
if (answer[2].classList.contains("faq__item-answer-show")) {
answer[2].classList.remove("faq__item-answer-show");
}
else {
answer[0].classList.remove("faq__item-answer-show");
answer[1].classList.remove("faq__item-answer-show");
answer[2].classList.add("faq__item-answer-show");
answer[3].classList.remove("faq__item-answer-show");
answer[4].classList.remove("faq__item-answer-show");
answer[5].classList.remove("faq__item-answer-show");
answer[6].classList.remove("faq__item-answer-show");
answer[7].classList.remove("faq__item-answer-show");
answer[8].classList.remove("faq__item-answer-show");
answer[9].classList.remove("faq__item-answer-show");
answer[10].classList.remove("faq__item-answer-show");
answer[11].classList.remove("faq__item-answer-show");
}
});
toggle[3].addEventListener("click", function (event){
event.preventDefault();
console.log("Клик по ссылки");
if (answer[3].classList.contains("faq__item-answer-show")) {
answer[3].classList.remove("faq__item-answer-show");
}
else {
answer[0].classList.remove("faq__item-answer-show");
answer[1].classList.remove("faq__item-answer-show");
answer[2].classList.remove("faq__item-answer-show");
answer[3].classList.add("faq__item-answer-show");
answer[4].classList.remove("faq__item-answer-show");
answer[5].classList.remove("faq__item-answer-show");
answer[6].classList.remove("faq__item-answer-show");
answer[7].classList.remove("faq__item-answer-show");
answer[8].classList.remove("faq__item-answer-show");
answer[9].classList.remove("faq__item-answer-show");
answer[10].classList.remove("faq__item-answer-show");
answer[11].classList.remove("faq__item-answer-show");
}
});
toggle[4].addEventListener("click", function (event){
event.preventDefault();
console.log("Клик по ссылки");
if (answer[4].classList.contains("faq__item-answer-show")) {
answer[4].classList.remove("faq__item-answer-show");
}
else {
answer[0].classList.remove("faq__item-answer-show");
answer[1].classList.remove("faq__item-answer-show");
answer[2].classList.remove("faq__item-answer-show");
answer[3].classList.remove("faq__item-answer-show");
answer[4].classList.add("faq__item-answer-show");
answer[5].classList.remove("faq__item-answer-show");
answer[6].classList.remove("faq__item-answer-show");
answer[7].classList.remove("faq__item-answer-show");
answer[8].classList.remove("faq__item-answer-show");
answer[9].classList.remove("faq__item-answer-show");
answer[10].classList.remove("faq__item-answer-show");
answer[11].classList.remove("faq__item-answer-show");
}
});
toggle[5].addEventListener("click", function (event){
event.preventDefault();
console.log("Клик по ссылки");
if (answer[5].classList.contains("faq__item-answer-show")) {
answer[5].classList.remove("faq__item-answer-show");
}
else {
answer[0].classList.remove("faq__item-answer-show");
answer[1].classList.remove("faq__item-answer-show");
answer[2].classList.remove("faq__item-answer-show");
answer[3].classList.remove("faq__item-answer-show");
answer[4].classList.remove("faq__item-answer-show");
answer[5].classList.add("faq__item-answer-show");
answer[6].classList.remove("faq__item-answer-show");
answer[7].classList.remove("faq__item-answer-show");
answer[8].classList.remove("faq__item-answer-show");
answer[9].classList.remove("faq__item-answer-show");
answer[10].classList.remove("faq__item-answer-show");
answer[11].classList.remove("faq__item-answer-show");
}
});
toggle[6].addEventListener("click", function (event){
event.preventDefault();
console.log("Клик по ссылки");
if (answer[6].classList.contains("faq__item-answer-show")) {
answer[6].classList.remove("faq__item-answer-show");
}
else {
answer[0].classList.remove("faq__item-answer-show");
answer[1].classList.remove("faq__item-answer-show");
answer[2].classList.remove("faq__item-answer-show");
answer[3].classList.remove("faq__item-answer-show");
answer[4].classList.remove("faq__item-answer-show");
answer[5].classList.remove("faq__item-answer-show");
answer[6].classList.add("faq__item-answer-show");
answer[7].classList.remove("faq__item-answer-show");
answer[8].classList.remove("faq__item-answer-show");
answer[9].classList.remove("faq__item-answer-show");
answer[10].classList.remove("faq__item-answer-show");
answer[11].classList.remove("faq__item-answer-show");
}
});
toggle[7].addEventListener("click", function (event){
event.preventDefault();
console.log("Клик по ссылки");
if (answer[7].classList.contains("faq__item-answer-show")) {
answer[7].classList.remove("faq__item-answer-show");
}
else {
answer[0].classList.remove("faq__item-answer-show");
answer[1].classList.remove("faq__item-answer-show");
answer[2].classList.remove("faq__item-answer-show");
answer[3].classList.remove("faq__item-answer-show");
answer[4].classList.remove("faq__item-answer-show");
answer[5].classList.remove("faq__item-answer-show");
answer[6].classList.remove("faq__item-answer-show");
answer[7].classList.add("faq__item-answer-show");
answer[8].classList.remove("faq__item-answer-show");
answer[9].classList.remove("faq__item-answer-show");
answer[10].classList.remove("faq__item-answer-show");
answer[11].classList.remove("faq__item-answer-show");
}
});
toggle[8].addEventListener("click", function (event){
event.preventDefault();
console.log("Клик по ссылки");
if (answer[8].classList.contains("faq__item-answer-show")) {
answer[8].classList.remove("faq__item-answer-show");
}
else {
answer[0].classList.remove("faq__item-answer-show");
answer[1].classList.remove("faq__item-answer-show");
answer[2].classList.remove("faq__item-answer-show");
answer[3].classList.remove("faq__item-answer-show");
answer[4].classList.remove("faq__item-answer-show");
answer[5].classList.remove("faq__item-answer-show");
answer[6].classList.remove("faq__item-answer-show");
answer[7].classList.remove("faq__item-answer-show");
answer[8].classList.add("faq__item-answer-show");
answer[9].classList.remove("faq__item-answer-show");
answer[10].classList.remove("faq__item-answer-show");
answer[11].classList.remove("faq__item-answer-show");
}
});
toggle[9].addEventListener("click", function (event){
event.preventDefault();
console.log("Клик по ссылки");
if (answer[9].classList.contains("faq__item-answer-show")) {
answer[9].classList.remove("faq__item-answer-show");
}
else {
answer[0].classList.remove("faq__item-answer-show");
answer[1].classList.remove("faq__item-answer-show");
answer[2].classList.remove("faq__item-answer-show");
answer[3].classList.remove("faq__item-answer-show");
answer[4].classList.remove("faq__item-answer-show");
answer[5].classList.remove("faq__item-answer-show");
answer[6].classList.remove("faq__item-answer-show");
answer[7].classList.remove("faq__item-answer-show");
answer[8].classList.remove("faq__item-answer-show");
answer[9].classList.add("faq__item-answer-show");
answer[10].classList.remove("faq__item-answer-show");
answer[11].classList.remove("faq__item-answer-show");
}
});
toggle[10].addEventListener("click", function (event){
event.preventDefault();
console.log("Клик по ссылки");
if (answer[10].classList.contains("faq__item-answer-show")) {
answer[10].classList.remove("faq__item-answer-show");
}
else {
answer[0].classList.remove("faq__item-answer-show");
answer[1].classList.remove("faq__item-answer-show");
answer[2].classList.remove("faq__item-answer-show");
answer[3].classList.remove("faq__item-answer-show");
answer[4].classList.remove("faq__item-answer-show");
answer[5].classList.remove("faq__item-answer-show");
answer[6].classList.remove("faq__item-answer-show");
answer[7].classList.remove("faq__item-answer-show");
answer[8].classList.remove("faq__item-answer-show");
answer[9].classList.remove("faq__item-answer-show");
answer[10].classList.add("faq__item-answer-show");
answer[11].classList.remove("faq__item-answer-show");
}
});
toggle[11].addEventListener("click", function (event){
event.preventDefault();
console.log("Клик по ссылки");
if (answer[11].classList.contains("faq__item-answer-show")) {
answer[11].classList.remove("faq__item-answer-show");
}
else {
answer[0].classList.remove("faq__item-answer-show");
answer[1].classList.remove("faq__item-answer-show");
answer[2].classList.remove("faq__item-answer-show");
answer[3].classList.remove("faq__item-answer-show");
answer[4].classList.remove("faq__item-answer-show");
answer[5].classList.remove("faq__item-answer-show");
answer[6].classList.remove("faq__item-answer-show");
answer[7].classList.remove("faq__item-answer-show");
answer[8].classList.remove("faq__item-answer-show");
answer[9].classList.remove("faq__item-answer-show");
answer[10].classList.remove("faq__item-answer-show");
answer[11].classList.add("faq__item-answer-show");
}
});
Написано
более трёх лет назад
Не понятно куда запушились коммиты в гите???
Вячеслав Мухин
@slavaweb
Автор вопроса
Отобразились, спустя час. Все ок.
Написано
более трёх лет назад
Войдите на сайт
Чтобы задать вопрос и получить на него квалифицированный ответ.
Войти через центр авторизации
Закрыть
Реклама