Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

150
Visualizações
JS Toggle Submenu within Mega Menu

The issue I'm having is, creating a submenu inside another menu.

Demo: LIVE DEMO (Important, cause CSS is needed as well

$(function () {
  // Desktop Menu
  var categoriesMenu = $(".list-ausbildung-categories li");
  var triggerMenu = $(".dropdown-submenuSide");
  var highlightsList = $(".list-ausbildung-highlights");
  var submenuList = $(".list-ausbildung-submenu");

  $('.list-ausbildung-categories').on('click', 'li', function () {

      if( $(this).hasClass('active') ){
          triggerMenu.removeClass('asg-gray-bg-200');
          $(".dropdown-submenuSide .list-ausbildung-submenu ul").html('');
      } else {
          highlightsList.hide();
          submenuList.show();
          triggerMenu.addClass('asg-gray-bg-200');

          $('li.active').removeClass('active');
          $(this).addClass('active');

          var subMenu = $(this).find(".dropdown-submenu").html();

          $(".dropdown-submenuSide .list-ausbildung-submenu ul").html(subMenu);
      }
  });

  $('.asg-megamenu div[class^="col"]:first-child').on('click', function () {
      categoriesMenu.removeClass('active');
      triggerMenu.removeClass('asg-gray-bg-200');
      submenuList.hide();
      highlightsList.show();
  });
});

I'm having this Bootstrap Mega Menu, which also contains a submenu (Column 2). On click, it should hide Column 3, and show the submenu items. (it does its job)

Currently, I'm grabbing the submenu content with jquery html() and then placing it on the third column (probably not the cleanest method).

The problem: whenever I close a submenu and click again, it won't open back.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It looks like currently, the active class isn't removed on the second click. Instead, it just clears out the HTML of column three. We could fix that by adding a line to remove the active class when we hide the submenu.

if( $(this).hasClass('active') ){
    $(this).removeClass('active'); // add in this line here so it will trigger properly on the next click
    triggerMenu.removeClass('asg-gray-bg-200');
    $(".dropdown-submenuSide .list-ausbildung-submenu ul").html('');
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda