0

I've been looking around and I feel like i'm really jumping a learning curve here and my head is about to explode from searching so much and coming up with nothing.

My problem is that I have a horizontal menu, designed with unordered lists, and to make it a dropdown menu i nested unordered lists in the first unordered list.

<ul class="top-level">
   <li><a href="#"></a>
       <ul class="dropdown">
          <li><a href="#"></a>
          </li>
       <ul>
   <li>
</ul>

Now, the nested unordered list is set to "Display:None;".

Since I have all the dropdown lists in the same class, when I try to toggle the 'Display:None;' attribute to 'Display: Block' ALL of the dropdown lists get toggled.

I know I can probably put each of the dropdown lists into their own seperate classes, but is there a way to do this with an array? To be able to click on a top-level list item and bring the appropriate dropdown list.

Thanks for help

2 Answers 2

2
$("ul.top-level li").click(function(event) {
    $(this).find("ul.dropdown").toggle();
});
Sign up to request clarification or add additional context in comments.

Comments

0

Something like that:

$(".top-level").on("click", "a", function() {
  $(this).next("ul.dropdown").toggle(); // Show / hide the corresponding sub-menu
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.