Sfoglia il codice sorgente

faq toggle answers

bach 3 anni fa
parent
commit
ead01c9061
1 ha cambiato i file con 11 aggiunte e 3 eliminazioni
  1. 11 3
      web/themes/custom/eql/scripts/main.js

+ 11 - 3
web/themes/custom/eql/scripts/main.js

@@ -27,10 +27,18 @@ for (let i = 0; i < questions.length; i++) {
 
 
 function toggleFaq(event) {
-  console.log(event);
+  console.log(event, this);
+  // fermé tout
   for (let i = 0; i < answers.length; i++) {
-  const answer = answers[i]
-  answer.classList.toggle('opened');}
+    answers[i].classList.remove('opened');  
+  }
+  // la réponse correspndante a la question clické
+  //           | this c'est l'élément sur le quel on a clické
+  //           |    |le parent |la réponse dans le parent
+  let answer = this.parentNode.querySelector('.field--name-field-reponse');
+  // console.log(answer); 
+  answer.classList.add('opened');
+  
 }
 
 // fonction pour attribuer la class du parents