Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

149
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda