A
A
AbsolvoTe2018-02-04 10:30:19
JavaScript
AbsolvoTe, 2018-02-04 10:30:19

How to collapse a menu when clicking on a menu item?

Hello!

$(".toggle-menu").click(function() {
    $(this).toggleClass("on");
    $(this).parent().next().find(".hidden-menu").slideToggle();
    return false;
  });


Unsure of correctness. It turned out like this:
$(".toggle-menu").click(function() {
    $(this).toggleClass("on");
    $(this).parent().next().find(".hidden-menu").slideToggle();
    return false;
  });

  $(".hidden-menu ul li a").click(function() {
    $(".toggle-menu").removeClass("on");
    $(".hidden-menu").hide();
    return false;
  });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jaroslaw Goszowski, 2018-02-04
@goszowski

Maybe put the button and menu on the wrapper and only use toggleClass() on the wrapper.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question