-
Notifications
You must be signed in to change notification settings - Fork 0
/
dropDown.js
29 lines (28 loc) · 845 Bytes
/
dropDown.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
function dropDownActived(){
const dropDowns = document.querySelectorAll(`[data-tg="dropDown"]`);
document.addEventListener('click', function(event) {
if (!Array.from(dropDowns).some(dropDown => dropDown.contains(event.target))) {
dropDowns.forEach(dropDown => {
const div = dropDown.querySelector('div');
div.removeAttribute('data-dropon');
});
}
});
dropDowns.forEach(dropDown => {
const div = dropDown.querySelector('div');
dropDown.querySelector('button').addEventListener('click', function() {
if (div.getAttribute('data-dropon') === '') {
removeAttr()
} else {
removeAttr();
div.setAttribute('data-dropon', '');
}
});
});
function removeAttr() {
document.querySelectorAll(`[data-dropon]`).forEach((d => {
d.removeAttribute(`data-dropon`);
}))
}
}
export{dropDownActived}