JavaScript Javascript toggle menu -issue with sub-menues javascript toggle menu button,javascript toggle menu script,javascript toggle

I'm working on a responsive menu for a quite complex website. The horizontal menu collapses to a vertical one for smaller screens and I've used javascript to toggle the sub-menu items open/closed when clicked.The product section is the only sub-menu that has another sub-menu a level deeper and it's not quite working for it as only the third level items close again on click, but not the parent item.

Here's the code

<nav id="navigation">
<ul id="nav-list"> 
    <li class="nav-list_item nav-about"><a target='_blank' href="....">About us</a>
        <div id="about-drop" class="dropdown">
            <ul>
                <li>....</li>
                <li>....</li>
            </ul>
        </div>
    </li>
    <li class="nav-list_item nav-products"><a target='_blank' href="....">Products</a>
        <div id="prod-drop" class="dropdown">
            <div id="subnav_products1" class='targetDiv'>
                <div class="drop-section">
                    <h5 class="nav-title">Purpose</h5>
                    <ul>
                        <li>...</li>
                        <li>...</li>
                    </ul>
                </div>
                <div class="drop-section">
                    <h5 class="nav-title">Series</h5>
                    ul>
                    <li>...</li>
                    <li>...</li>
                    </ul>
            </div>
        </div>
        </div>
    </li>
</ul>

And the javascript :

if ($(window).width() <= 760) {
$('li.nav-list_item').click(function(){
    $('li.nav-list_item').not(this).find('ul').hide();
    $(this).find('ul').toggle();
});
}

I think it might be because when the parent item (products) is clicked the ul close as specified in the javascript but the nav-title items (Purpose/ Series) are still open and can't be closed. I've been trying to work this out but just can't get it to work that when the title items are being clicked the third level menu closes and when the parent item(Products) is clicked the title items close. Any suggestions?

Answer:1

First off, I do not know how to debug your code as what you provided is not a working example. Head over to Codepen and create a pen where we can reproduce the issues.

Apart from that it is possible to implement the navigation with css only using hidden radio buttons or active states.

Answer:2

How to open the modal after a ajax call on success i need to trigger the modal window automatically <a class="main_blue_button" href="#complete_application_modal" id="applicationBtn">SIGN UP<...

How to open the modal after a ajax call on success i need to trigger the modal window automatically <a class="main_blue_button" href="#complete_application_modal" id="applicationBtn">SIGN UP<...

I am facing issue while making a dynamic table with dynamic rowspan. My json is a array of objects. And the element objects are also arrays. The element arrays should come as the no of dynamic rowspan....

I am facing issue while making a dynamic table with dynamic rowspan. My json is a array of objects. And the element objects are also arrays. The element arrays should come as the no of dynamic rowspan....

  1. angularjs repeat start end
  2. angularjs repeat start
  3. angularjs ng-repeat-start
  4. angularjs ng-repeat start from index
  5. angularjs ng-repeat start end
  6. angularjs ng-repeat-start example
  7. angularjs ng-repeat-start filter
  8. angularjs ng-repeat-start nested
  9. angularjs ng-repeat-start table
  10. angularjs data-ng-repeat-start

I have to display the content in a grid. All items are div's with random height, and I need to have control over how they are displayed. It is a responsive UI with 4-cols, 3-cols and 1-cols. Assume ...

I have to display the content in a grid. All items are div's with random height, and I need to have control over how they are displayed. It is a responsive UI with 4-cols, 3-cols and 1-cols. Assume ...

  1. position div at bottom of parent
  2. position div in center
  3. position div at bottom of page
  4. position div relative to another div
  5. position div on top of another
  6. position div below another div
  7. position divided by time
  8. position divs side by side
  9. position div to right
  10. position div relative to parent
  11. position div in center of screen
  12. position div in center of parent
  13. position div bottom right of parent
  14. position div at bottom of screen
  15. position div inside div
  16. position div over image
  17. position div at top of page
  18. position div vertically center
  19. position div to right of another div
  20. position div at bottom of div

There are null and undefined in JavaScript. Are there any meaningful use cases of assigning undefined to a variable?

There are null and undefined in JavaScript. Are there any meaningful use cases of assigning undefined to a variable?