Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7851555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:12:43+00:00 2026-06-02T19:12:43+00:00

I’m trying to make a simple horizontal navigation bar with multiple levels (but for

  • 0

I’m trying to make a simple horizontal navigation bar with multiple levels (but for now, I’ve only made a navigation bar with one sublevel). I’m following this tutorial here with some modifications:

<ul id = "sample2">
    <li>
        <a href="#">About Us</a>
        <ul>
            <li><a href="#">Website</a></li>
            <li><a href="#">Creator</a></li>
        </ul>
    </li>
    <li>
        <a href="#">Our Products</a>
        <ul>
            <li><a href="#">Product 1</a></li>
            <li><a href="#">Product 2</a></li>
            <li><a href="#">Just give us money</a></li>
        </ul>
    </li>
    <li>
        <a href="#">FAQs</a>
        <ul>
            <li><a href="#">What is this?</a></li>
            <li><a href="#">Why should I care???</a></li>
        </ul>
    </li>
    <li>
        <a href="#">Contact</a>
        <ul>
            <li><a href="#">Telephone</a></li>
            <li><a href="#">Mobile Phone</a></li>
            <li><a href="#">E-mail</a></li>
        </ul>
    </li>
    <li><a href="#">Login</a></li>
</ul>

I used only one id on the main <ul> and I’m accessing the sublevels using #sample2 ul instead of using classes on those.

However, it simply doesn’t work when I use the JQuery codes:

$(function () {
    $('#sample2 ul').each(function () {
        $(this).parent().eq(0).hover(function () {
            $('#sample2 ul:eq(0)', this).show(100);
            }, function () {
            $('#sample2 ul:eq(0)', this).hide(100);
        });
    });
});

Again, I only changed the tutorial’s .dropdown class to #sample2 ul.

But it does work if I do the same way as the tutorial (i.e. assign either an id or a class on the sublevels), although I think it’s unnecessary since those sub-<ul>-s can be selected using css selectors.

What am I doing wrong? Are those sublevels really can only be selected using assigned classes/id on them?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:12:44+00:00Added an answer on June 2, 2026 at 7:12 pm

    This should do the trick. jsFiddle

    $(function () {
        $('#sample2').on('hover', 'li', showSubMenu);
        $('#sample2').on('mouseleave', hideSubMenus);
    });
    
    function showSubMenu(){
        $(this).siblings().children('ul').hide(100);
        $(this).children('ul').show(100);
    }
    function hideSubMenus(){
        $(this).find('ul').hide(100);
    }
    

    EDIT:
    It seems like you have some confusion about jQuery and how to use selectors (particularly selectors with context e.g. $(selector, context)).

    In your example, $('#sample2 ul') will select every ul that is a descendant of #sample 2. If you wanted to add the same hover effect to each ul, $('#sample2 ul').hover(handler) or $('#sample2 ul').on('hover', handler) will do that for you. The problem is, you can’t hover over hidden items. So what you really want is to select the li under #sample2 and attach your handler to their hover event.

    Within your hover event handler, you use the selector $('#sample2 ul:eq(0)', this). The ‘this’ in that selector provides the context within which the #sample2 ul:eq(0) will be looked for. In an event handler, this refers to the element tied to that event. In this case, the hovered-over li. Eq(0) has no place inside the quotes of the selector, and as a general rule, should be avoided as part of any jQuery selector. Because there is no #sample2 element within the context of this and because the :eq(0) malforms the selector, $('#sample2 ul:eq(0)', this) will return an empty jQuery object (nothing selected). What you wanted in your handler was $(this).children('ul'). Which will get the ul that is a direct child of the li currently hovered over.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.