3
0
Fork 0
mirror of https://github.com/nanoy42/coope synced 2024-11-16 00:13:12 +00:00
coope/staticfiles/dropdown.js

27 lines
954 B
JavaScript
Raw Normal View History

2019-09-22 13:32:40 +00:00
/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */
function dropdown(target) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
document.getElementById(target).classList.toggle("show");
}
// Close the dropdown menu if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}