SAE_S1.05_S1.06/js/faq.js

23 lines
944 B
JavaScript
Raw Normal View History

2024-01-16 00:23:27 +01:00
document.addEventListener("DOMContentLoaded", function() {
const faqelements = document.querySelectorAll('.faq-element');
2024-01-16 00:23:27 +01:00
faqelements.forEach(element => {
const questionBtn = element.querySelector('.faq-question-btn');
2024-01-16 00:23:27 +01:00
questionBtn.addEventListener('click', () => {
// Ferme toutes les autres réponses
faqelements.forEach(otherelement => {
if (otherelement !== element) {
otherelement.classList.remove('active');
otherelement.querySelector('.faq-reponse').style.display = 'none';
2024-01-16 00:23:27 +01:00
}
});
// Affiche ou masque la réponse de la question actuelle
element.classList.toggle('active');
const reponse = element.querySelector('.faq-reponse');
reponse.style.display = element.classList.contains('active') ? 'block' : 'none';
2024-01-16 00:23:27 +01:00
});
});
});