Line 10: | Line 10: | ||
// 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 (!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'); | |
</script> | </script> |
Revision as of 06:08, 27 October 2017