Solved

jquery to show hide div on mouse over

Posted on 2011-03-22
4
843 Views
Last Modified: 2012-05-11
I have built a menu bar with divs and the drop down menus are divs as well. On mouse over on the mainmenu, I need the dropdown menu to be visible and on mouse out to be hidden. The drop down menu has table, anchors which the user can click on. I use jquery to showide  the div. The problem I have is that after the dropdownmenu is visible and the mouse is inside the dropdowndiv, the dropdown gets hidden. I have attached the code below. Please advise as to how I can make the dropdown stay visible as long as the user is inside the dropdowndiv. Thanks
function DropMenu1MouseOver() 
	{
          $("#divDropMenu1").css('display', 'block');

        }

   function DropMenu1MouseOut()
        {
            $("#divDropMenu1").css('display', 'none');          
        }

  $(document).ready(function () {
            $('#divMainMenu1').bind('mouseover', DropMenu1MouseOver);
            $('#divMainMenu1').bind('mouseout', DropMenu1MouseOut);
});


 <div id="divMainNavigationContainer" runat="server">
                                <div id="divMainMenuContainer">
                                    <div id="divMainMenu1" class="MainMenus"  onclick="MainMenuClick(1)">
                                        Office Supplies
                                    </div>
				    //other mainmenu stuff
				</div>
 </div>

<div id="divDropMenu1" class="DropMenus">
//other stuff
<a href="something">somestuff</a>
</div>

Open in new window

0
Comment
Question by:TrialUser
  • 2
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 35195350
Try to use .hover instead mouseover and mouseout : http://api.jquery.com/hover/
 
$('#divMainMenu1').hover(DropMenu1MouseOver,DropMenu1MouseOut);

Open in new window

0
 

Author Comment

by:TrialUser
ID: 35195579
I am atually having to attach the events to both divMainMenu1 and to divDropMenu1 and so on. That is
because, when the mouse overs divdropmenu1, divmainmenu1's mouseout event fires.  SO either of the following works. But it seems like a not so elegant way to do it since the same methods are
being called twice. Any thoughts on how this can be achieved?

//begin method 1
$('#divMainMenu1').hover(DropMenu1MouseOver, DropMenu1MouseOut);
                $('#divDropMenu1').hover(DropMenu1MouseOver, DropMenu1MouseOut);gi
//end method1

//begin method 2  

         $('#divMainMenu1').bind('mouseover', DropMenu1MouseOver);
            $('#divMainMenu1').bind('mouseout', DropMenu1MouseOut);
            $('#divDropMenu1').bind('mouseover', DropMenu1MouseOver);
            $('#divDropMenu1').bind('mouseout', DropMenu1MouseOut);
//end method 2
0
 

Author Closing Comment

by:TrialUser
ID: 35429776
thx a ton
0
 
LVL 82

Expert Comment

by:leakim971
ID: 35430153
You're welcome! Thanks for the points!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now