Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
46 lines (32 loc) · 1.38 KB
/
Copy pathscript.js
File metadata and controls
46 lines (32 loc) · 1.38 KB
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
document.addEventListener('DOMContentLoaded', () => {
// assign the button click
document.querySelectorAll('.dropbtn').forEach(btn => {
btn.addEventListener('click', e => {
// first close all
document.querySelectorAll('.dropdown-content').forEach(div => div.classList.remove('show'))
// open the one you want which is CLOSEST
e.target.closest('.dropdown').querySelector('.dropdown-content').classList.add('show');
})
})
// catch the click outside
document.addEventListener('click', e => {
if (e.target.classList.contains('dropbtn')) return;
document.querySelectorAll('.dropdown-content').forEach(div => div.classList.remove('show'))
})
})
document.addEventListener('DOMContentLoaded', () => {
// assign the button click
document.querySelectorAll('.drpbtn').forEach(btn => {
btn.addEventListener('click', e => {
// first close all
document.querySelectorAll('.drpdown-content').forEach(div => div.classList.remove('show'))
// open the one you want which is CLOSEST
e.target.closest('.drpdown').querySelector('.drpdown-content').classList.add('show');
})
})
// catch the click outside
document.addEventListener('click', e => {
if (e.target.classList.contains('drpbtn')) return;
document.querySelectorAll('.drpdown-content').forEach(div => div.classList.remove('show'))
})
})