menu

Questions & Answers

How to close the menu one by one when clicked again

I have a menu with three levels of nesting. I open each one in turn with the following code:

  $(".menu-item-has-children").click(function (event) {
    event.preventDefault();
    $(this).children(".sub-menu").slideToggle();
  });

The first level of nesting opens well. And when I try to open the next level, the previous one closes. And when I open it again, the next one is open. How can I fix this and make it possible to open and close the menu one by one? Menu structure

Comments:
2023-01-07 20:33:01
Edit the code snippet to include enough HTML to have a reproducible example.
Answers(0) :