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

  • Home
  • SEARCH
  • 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 1045179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:56:42+00:00 2026-05-16T15:56:42+00:00

When I hover over the parent links in my menu the class toggle-active is

  • 0

When I hover over the parent links in my menu the class “toggle-active” is added to a span tag so the arrow image is changed. I also want this class to be added to the span tag when I’m hovering over the child links of the parent link inside the .sub-menu container, but I cannot get it to work. Here is the structure of the menu with the jQuery I’m using::

jQuery(".sub-menu").hide(); 

jQuery("#gallery-nav").find("li").each(function() {

  if (jQuery(this).find("ul").length > 0) {

    jQuery("<span class=\"gallery-toggle-button\">").appendTo(jQuery(this).children(":first"));

    jQuery("#gallery-nav li a").hover(function(){
      jQuery(this).children(".gallery-toggle-button").addClass("toggle-active");
    }, function () {
      jQuery(this).children(".gallery-toggle-button").removeClass("toggle-active");
    });

    jQuery("#gallery-nav li a").hover(function(){
      jQuery(this).next("ul").slideDown('fast');
    });

    jQuery("#gallery-nav li ul").hover(function(){
      jQuery(this).slideDown('fast');
    }, function () {
      jQuery(this).slideUp('fast');
    });

    jQuery("#gallery-nav li ul").hover(this).prev(function(){
      jQuery("#gallery-nav li a").children(".gallery-toggle-button").addClass("toggle-active");
    }, function () {
      jQuery("#gallery-nav li a").children(".gallery-toggle-button").removeClass("toggle-active");
    });
  };
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
  <li>
    <a href="#">Link 1 <span class="toggle-active"></span></a>
    <ul class="sub-menu">
      <li><a href="#">Sub link 1</a></li>
    </ul>
  </li>
</ul>
  • 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-05-16T15:56:43+00:00Added an answer on May 16, 2026 at 3:56 pm

    I see a few problems.

    .sub-menu
    

    has that dash so it doesn’t match this ul here

    <ul class="submenu">
    

    Next, Javascript closures are tricky. In this bit of code here, “this” stops meaning the “li” and starts meaning the element you matched on, which is the “a”.

    jQuery("#gallery-nav li a").hover(function(){
        jQuery(this).children(... // <- "this" now means "a", not "li"
    

    In other words, you should do it this way

    var top_li = this;
    jQuery("#gallery-nav li a").hover(function(){
        jQuery(top_li).children(...
    

    Finally, I’d just do the whole thing thusly.

    $(function() {
      $(".sub-menu").hide();
      $("#gallery-nav li").each(function() {
        if ($(this).find("ul").length) {
          $(this).addClass("top_menu_li");
          $(this).find("a").eq(0).addClass("top_menu_a").append($("<span/>"));
        }
      });
      $(".top_menu_li").each(function() {
        var top_menu_li = $(this);
        top_menu_li.hover(function() {
          top_menu_li.find(".top_menu_a span").addClass("toggle-active");
          top_menu_li.find(".sub-menu").show();
        }, function() {
          top_menu_li.find(".top_menu_a").removeClass("toggle-active");
          top_menu_li.find(".sub-menu").hide();
        });
      });
    });
    <html>
      <head>
        <script type="text/javascript" src="http://www.google.com/jsapi"></script>
        <script type="text/javascript">
          google.load("jquery", "1");
        </script>
      </head>
      <body>
        <ul id="gallery-nav">
          <li>
            <a href="#">Link 1</a>
            <ul class="sub-menu">
              <li><a href="#">Sub link 1</a></li>
            </ul>
          </li>
          <li>
            <a href="#">Link 2</a>
            <ul class="sub-menu">
              <li><a href="#">Sub link 2</a></li>
            </ul>
          </li>
        </ul>
      </body>
    </html>

    Edited

    Now it adds the classes and spans. ghostpool, “find” targets children, so it only shows the correct sub navigation. Copy and paste that HTML and try it for yourself.

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

Sidebar

Related Questions

I have coded a css dropdown menu. But when I hover over the parent
I would like to create a hover over my navbar links like the ones
I'm trying to get a dropdown menu to open when I hover over the
I'm using HtmlAgilityPack. I hover over the parent node and its ChildNodes show several
So I have some HTML like this: <a class=tooltip title=my tool tip> Hover over
i want hover over an image -> which is in an link during i'm
When I use firebug and hover over the parent box nothing is shown. I
The site: http://coqinn.lexcorp.ca/rooms-and-suites/ Hover over the Rooms & Suites menu item and you'll see
When I hover over the whole button, I would like it to appear over
When you hover over a point in a Highcharts chart, you get a nice

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.