forked from Peruf/Testi-Chiesa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
30 lines (25 loc) · 771 Bytes
/
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
function Dropdown(e, index) {
var tobedisplayed = document.getElementsByName("dropdowntobedisplayed")[index]
tobedisplayed.classList.toggle("show")
}
window.onclick = function(event) {
if (!event.target.matches('.button')) {
var dropdowns = document.getElementsByClassName("ContDrop");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
window.addEventListener("load", function() {
var dropdowns = Array.from(document.getElementsByName("dropdown"))
dropdowns.forEach( (el, index) => {
el.addEventListener("click", function(e) {
var i = index
Dropdown(e, i)
})
})
})