Line 19: | Line 19: | ||
// Close the dropdown if the user clicks outside of it | // Close the dropdown if the user clicks outside of it | ||
− | window.onclick = function( | + | window.onclick = function(event) { |
− | if (! | + | if (!event.target.matches('.dropbtn')) { |
− | var | + | |
− | if ( | + | 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'); | ||
} | } | ||
+ | } | ||
} | } | ||
} | } |
Revision as of 06:49, 29 October 2017