Solved

jquery to show hide div on mouse over

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

776 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