Solved

jquery to show hide div on mouse over

Posted on 2011-03-22
4
850 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

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.
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

705 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