Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to make the sub-menus visible on click. I am using the default WP navigation.

In order to check which elements I need, I checked the source code and then used the corresponded classes in my code. First, the drop-downs are displayed when you hover and then they go up. Which probably means that the second part of the script works. What am I doing wrong? Any help will be much apreciated! Thank you!

What I have tried:

JavaScript
$(document).ready(function() {
  // Show hide popover
  $(". menu-item-623 a").click(function() {
    $(this).find("#sub-menu").slideToggle("fast");
  });
});
$(document).on("click", function(event) {
  var $trigger = $(".menu-item menu-item-type-custom menu-item-object-custom current-menu-ancestor current-menu-parent menu-item-has-children menu-item-623 first-child");
  if ($trigger !== event.target && !$trigger.has(event.target).length) {
    $(".sub-menu").slideUp("fast");
  }
});


HTML
<ul id="primary-menu" class="menu">

  <li class="menu-item menu-item-type-custom menu-item-object-custom 
       current-menu-ancestor current-menu-parent menu-item-has-children menu-
        item-623 first-child">

    <a href="#">Explore</a>

    <ul class="sub-menu">

      <li id="menu-item-563" class="menu-item menu-item-type-post_type menu-
       item-object-page current-menu-item page_item page-item-14 
      current_page_item menu-item-563 first-child"><a href="http://localhost:81/">Why </a></li>
      <li id="menu-item-562" class="menu-item menu-item-type-post_type menu-
        item-object-page menu-item-562 last-child"><a href="http://localhost:81/DEMO/who-already-joined/">Who </a>

      </li>
    </ul>
</ul>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900