-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
69 lines (58 loc) · 2.68 KB
/
script.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
document.addEventListener("DOMContentLoaded", function() {
//qna handler
const questions = document.querySelectorAll('.question-div');
questions.forEach(question => {
question.addEventListener('click', function() {
const answer = this.nextElementSibling;
const questionIcon = this.querySelector(".question-icon");
if (!answer.classList.contains('hide')) {
answer.classList.add('hide');
questionIcon.style.transform = "rotate(0)";
} else {
document.querySelectorAll('.answer').forEach(ans => {
ans.classList.add('hide');
});
document.querySelectorAll(".question-icon").forEach(icon => {
icon.style.transform = "rotate(0)";
})
answer.classList.remove('hide');
questionIcon.style.transform = "rotate(45deg)";
}
});
});
//Drop-down handler
const dropdowns = document.querySelectorAll('.dropdown');
dropdowns.forEach((dropdown, i) => {
const dropdownContent = document.getElementsByClassName('dropdown-content')[i];
const arrowIcon = dropdown.querySelector('.arrow-icon');
const languageSpan = dropdown.querySelector('span');
dropdown.addEventListener('click', (event) => {
if (dropdownContent.classList.contains('hide')) {
closeAllDropdowns();
dropdownContent.classList.remove('hide');
arrowIcon.innerHTML = '▴'; // Up arrow
} else {
dropdownContent.classList.add('hide');
arrowIcon.innerHTML = '▾'; // Down arrow
}
event.stopPropagation();
});
// Handle language selection
const options = dropdownContent.querySelectorAll('div');
options.forEach(option => {
option.addEventListener('click', () => {
languageSpan.innerHTML = option.textContent + ' <b class="arrow-icon">▾</b>';
dropdownContent.classList.add('hide');
arrowIcon.innerHTML = '▾'; // Down arrow
});
});
});
// Close all dropdowns when clicked out of the select box
document.addEventListener('click', closeAllDropdowns);
function closeAllDropdowns() {
const dropdownContents = document.querySelectorAll('.dropdown-content');
const arrowIcons = document.querySelectorAll('.arrow-icon');
dropdownContents.forEach(content => content.classList.add('hide'));
arrowIcons.forEach(icon => icon.innerHTML = '▾'); // Down arrow
}
});