Solved

jquery to show hide div on mouse over

Posted on 2011-03-22
4
846 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
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 elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

809 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