简体   繁体   中英

The back button does not work in the responsive menu

What I want to do is to return to the previous menu when the return button is clicked, can you help? I'm leaving a link on how to write the code here

const submenutitle = document.querySelector('.submenutitle');

https://codepen.io/tolgagnydnn/pen/abWmMpp

The problem was you had two listeners and the second (the back button) was being overwritten by the first (because the back button is part of the group of listeners from the first set). Essentially, the back button had 2 event listeners on it. I consolidated them. I had to change some of the code, so that it would find the right element to add/remove classes from:

for (const mobilemainmenuitem of mobilemainmenuitems) {
  mobilemainmenuitem.addEventListener("click", (e) => {
    const submenu = e.target;
    if (submenu.classList.contains("btn"))
      submenu
        .closest(".mobilesubmenu")
        .classList.remove("showleft", "showvisibility");
    else
      submenu
        .closest("li")
        .querySelector(".mobilesubmenu")
        .classList.add("showleft", "showvisibility");
  });
}

https://codepen.io/kinglish/pen/OJmRevq?editors=1111

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM