I was given two functions that are nearly identical, but one uses a parameter.
function handleBlur() {
const list = event.currentTarget.closest("#nav ul");
if (!event.relatedTarget || !list.contains(event.relatedTarget)) {
closeNav();
}
}
function handleDropdownBlur(btn) {
const list = event.currentTarget.closest("#nav ul");
if (!event.relatedTarget || !list.contains(event.relatedTarget)) {
closeDropdown(btn);
}
}
I was able to change the first function to work properly by simply adding event
as the function parameter.
function handleBlur(event) {
const list = event.currentTarget.closest("#nav ul");
if (!event.relatedTarget || !list.contains(event.relatedTarget)) {
closeNav();
}
}
How would I change the second function to not warn of deprecation?
I tried adding event
as both a first and second parameter, but this breaks the functionality.
The function is called later in the code like this:
dropdowns.forEach((dropdown) => {
const list = dropdown.querySelectorAll("li a");
list[list.length - 1].addEventListener("blur", (event) => {
handleDropdownBlur(dropdown.previousElementSibling);
});
});