I'm getting an error in IE:
Object doesn't support property or method 'matches'".
Tried to close the dropdown list when clicking outside.
Below is the code:
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">Options</button>
<div id="myDropdown" class="dropdown-content">
<a href="#directory" class="directory">Content Directory</a>
<a href="#objective" class="objective">Objectives</a>
<a href="#reference" class="reference">Reference</a>
<a href="#help" class="help">Help</a>
</div>
</div>