onokumus / metismenu

A collapsible jQuery menu plugin
https://onokumus.github.io/metismenu/
MIT License
1.96k stars 487 forks source link

Clicking a link prevent navigate to the page #179

Open dangelion opened 5 years ago

dangelion commented 5 years ago

Hi I need to prevent that clicking on a link, it navigates to the url. I just want it opens the submenu.

I'm using version 3.0.4 with this code:

 <ul id="metismenu">
    <li>
      <a href="/about" aria-expanded="false">Menu 1</a>
      <ul>
        <li>Test</li>
        <li>Test</li>
      </ul>
    </li>
    <li>
      <a href="/about" aria-expanded="false">Menu 2</a>
      <ul>
        <li>Test</li>
        <li>Test</li>
      </ul>
    </li>
  </ul>

    $("#metismenu").metisMenu({
      preventDefault: true
    });

For example: if I click "Menu 1" it navigates to the page /about instead I just want it opens the submenu. preventDefault: true seems to not working

Here a Codepen to clearly see this bug: https://codepen.io/anon/pen/LaMgJw

Some help?

onokumus commented 5 years ago

What is your project structure?

dangelion commented 5 years ago

Hi @onokumus it's this one: https://github.com/roots/sage

HTML code is inside /resources/views/partials/header.blade.php JS code is inside /resources/assets/scripts/routes/common.js

Let me know if I answerd

onokumus commented 5 years ago

I don't see metisMenu in this repository.

dangelion commented 5 years ago

@onokumus That's the third-party boilerplate I'm using, it's not mine. The code is placed where I said before.

I made a codepen https://codepen.io/anon/pen/LaMgJw where you clearly see this bug. Let me know if helps

dangelion commented 5 years ago

Hi @onokumus have you seen the bug in the codepen? Let me know, thanks