/
app.js
26 lines (23 loc) · 824 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// question and answer node list
const faqList = document.querySelectorAll('.question');
const answerList = document.querySelectorAll('.answer-paragraph');
faqList.forEach((question, i) => {
question.addEventListener('click', () => {
let iOf = 0;
let activeI = 0;
let permission = true;
for (const questionOf of faqList) {
if (questionOf.classList.contains('active-q')) {
questionOf.classList.toggle('active-q');
answerList[iOf].classList.toggle('active-a');
activeI = iOf;
permission = false;
}
iOf++;
}
if (activeI !== i || permission) {
question.classList.toggle('active-q');
answerList[i].classList.toggle('active-a');
}
});
});