I've encountered an issue with my code that involves the following functionalities: 1: When a user clicks a button, it toggles the drop-down menu on or off. 2: Clicking anywhere within the webslides element should close the menu if it's displayed.
The problem arises when the webslides element is positioned beneath the button. I want users to be able to click on the header to also hide the menu, but this function doesn't seem to work as intended. Instead, the button fails to display the menu at all, regardless of how many times I attempt to open it,
var menu = document.getElementsByClassName("dropdown-content")[0];
var header = document.getElementById('header');
var webslidesBody = document.getElementById('webslides');
function lessonSelectionFunction() {
if (menu.style.display === "none") {
menu.style.display = "block";
} else {
menu.style.display = "none";
}
}
webslidesBody.onclick = function() {
menu.style.display = "none";
}
header.onclick = function() {
menu.style.display = "none";
}
<html>
<head>
...