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 1092307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:39:45+00:00 2026-05-16T23:39:45+00:00

hi all im building a menu and im trying to put an hover effect

  • 0

hi all im building a menu and im trying to put an hover effect on each menu item
but… when i hover everything is working great and i get the html i want and the menu item has a backgruond image.

but the unhover effect dosnt fire most of the times. i found out that if i move my mouse horziantly across the ul menu it works fine. but if my mouse does a vertical move across the li item it dosnt fire.
my code is this:

 $("ul.menu li").hover(ChangeToHoverMenuItem, ChangeBackMenuItem);
 function ChangeToHoverMenuItem()
 {
    var currLi = $(this);
    lastLi = currLi;
    var currMenuItemText = currLi.find("a").text();
    currLi.html("");

    currLi.append("<div style='float:right;'><div class='right_item_hov'></div>" +
                "<a class='item_menu_hov'>" +
                currMenuItemText +
                "</a>" +
                "<div class='left_item_hov'></div></div>");
 }

 function ChangeBackMenuItem ()
 {
     var currLi = $(this);
     var currMenuItemText = currLi.find("a").text();

     currLi.html("");
     currLi.append("<a>" + currMenuItemText + "</a>");

 }

     <div class="menu_middle">
    <ul class="menu">
        <li>
            <a>
                main
            </a>
        </li>
        <li>
            <a>
                gallery
            </a>
        </li>
        <li>
            <a>
                event
            </a>
        </li>
        <li>                
            <a>
               about
            </a>
        </li>
        <li>
            <a>
                contact
            </a>
        </li>
    </ul>
</div>

thank you

  • 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-16T23:39:45+00:00Added an answer on May 16, 2026 at 11:39 pm

    The strange thing is, that there are two mouseenter() events on sibling elements without a mouseleave() event in between.

    One idea is to register the mouseenter() and mouseleave() event instead of using hover(). hover() should do the same, but how knows. If this works, the problem lies in the implementation of hover() but I don’t think so.

    
    $("ul.menu li")
      .mouseenter(ChangeToHoverMenuItem)
      .mouseleave(ChangeBackMenuItem);
    

    Another idea is to ensure that the mouseleave() code was executed. In your “doHover” handler you can check if there is anhoveredItem. If so, you can call the ChangeBackMenuItem function with the still hovered item as this. To ensure that the “unhover” handler is called when you leave your ul, you need a mouseleave event on this, that does the same. This solution relies on a working mouseleave on the ul element.

    
    $(function() {
    
     var hoveredItem = null;
    
     function ChangeToHoverMenuItem()
     {
        if (hoveredItem) {
           ChangeBackMenuItem.call(hoveredItem);
        }
        hoveredItem = this;
    
        var currLi = $(this);
        lastLi = currLi;
        var currMenuItemText = currLi.find("a").text();
        currLi.html("");
    
        currLi.append("" +
                    "" +
                    currMenuItemText +
                    "" +
                    "");
     }
    
     function ChangeBackMenuItem ()
     {
         var currLi = $(this);
         var currMenuItemText = currLi.find("a").text();
    
         currLi.html("");
         currLi.append("" + currMenuItemText + "");
         hoveredItem = null;
    
     }
    
     $("ul.menu li").hover(ChangeToHoverMenuItem, ChangeBackMenuItem);
     $("ul.menu").mouseleave(function() {
       if (hoveredItem) {
         ChangeBackMenuItem.call(hoveredItem);
         hoveredItem = null;
       }
     });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.