Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Menu tweak

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #195275
    Black Mamba
    Participant

    Currently, if I got a menu open and click the submenu it closes the menu. How do I prevent that? I want it to do nothing.

    http://codepen.io/anon/pen/vEWdRR

    #195299
    Senff
    Participant

    First of all, you’ve used invalid markup. Within an OL or a UL, the direct descendants have to be LI’s. A DIV can only be used if it’s within an LI.

    To fix your issue, add this to your code:

    $('.submenu').on('click', function(e){
      e.stopPropagation();
    });
    

    This makes sure that clicking on a SUBmenu does not “bubble up” and triggers the click on the (parent) menu.

    #195304
    Black Mamba
    Participant

    It worked. Thank you.

    Well, it’s working like I want it to.
    What could be the issues caused by using DIVs?
    Should I change that? How?

    #195425
    shaneisme
    Participant

    If you want proper markup without breaking anything, this is how you could do it:

    http://codepen.io/drainpip/pen/dPJPMx

    #195456
    Black Mamba
    Participant

    @shaneisme
    Thank you very much. In the meantime a few things have changed but instead of “polluting” this thread I think I should probably open a new one.

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Menu tweak’ is closed to new replies.