I seem to be facing a challenge with a JavaScript script that is being used on a menu. The menu is styled differently for desktop and smaller devices, and I would like the script to only impact the menu when the screen width is less than a certain value. How can I make this happen? Here's the script:
var dropdown = document.getElementsByClassName("dropdown-btn");
var i;
for (i = 0; i < dropdown.length; i++) {
dropdown[i].addEventListener("click", function() {
var dropdownContent = this.nextElementSibling;
if (dropdownContent.style.display === "block") {
dropdownContent.style.display = "none";
} else {
dropdownContent.style.display = "block";
}
});
}