css - multilevel dropdown menu toggle not working using jquery -


first of let me tell i'm little weak in jquery helping here let me learn lot jquery. i'm trying expand level 2 li menu using jquery alas after searching google while i'd post problem in here. problem html skeleton below before i'm working on wp nav.

<div class="mobile-menu">     <div id="megamenu">         <div id="megamenutoggle"></div>         <ul id="megauber>             <li>                 <ul>                     <li>                         <ul>                             <li></li>                             <li></li>                             <li></li>                         </ul>                     </li>                    <li></li>                 </ul>              </li>              <li></li>              <li></li>              <li></li>          </ul>     </div> </div> 

now problem can open level 1 li in toggle while opening level 2 it's not toggling. here css code toggling.

.mobile-menu #megamenu #megauber > li.active > + ul {     display: block !important;}  .mobile-menu #megamenu #megauber > li > + ul {     display: none !important;}  .mobile-menu #megamenu #megauber > li > ul > li.actives > + ul {     display: block !important;} .mobile-menu #megamenu #megauber > li > ul > li > + ul {     display: none !important} 

here jquery code i've written working level 1 li & megamenutoggle div toggle not level 2.

jquery(function($){     $(".mobile-menu #megamenu #megamenutoggle").on('click', function(){       $(".mobile-menu #megamenu #megauber").slidetoggle( "slow" );     });      $('.mobile-menu #megamenu #megauber li a').on('click',function(event){       console.log('first drop');       event.stoppropagation();       $(".mobile-menu #megamenu #megauber li")         .not($(this).parent())         .removeclass("active");         $(this).parent().toggleclass("active");      });      $('.mobile-menu #megamenu #megauber li ul li a').on('click',function(event){       console.log('second drop');       event.stoppropagation();       $("#megauber li")         .not($(this).parent())         .removeclass("active");         $(this).parent().toggleclass("active");        $("#megauber li ul li")         .not($(this).parent())         .removeclass("actives");         $(this).parent().toggleclass("actives");     }); }); 

ok i've got working version: fiddle

the fix:

$(function () {     $('#megauber').find('a').click(function (e) {         e.stoppropagation();         $(this).parent().toggleclass("active");     }); }); 

and bit of css needed actives changed active

.mobile-menu #megamenu #megauber > li > ul > li.active > + ul {     display: block !important; } 

this should nest infinitely.

here's what's happening:

the jquery looks list right id. took out other selector text because id should exist once on page there's no need more specific in selector, doing. once finds element looks it's children find() function , attaches click() events of them. click events reference parent() element goes 1 level up, , puts active class on them. opens menu.

the slidetoggle bit doesn't work this. if want effect you'll have rethink how whole thing works. won't go that.

i'm not sure you're trying ubermenu, i've never used it. must have links in html, not <li> elements.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -