?
Solved

jquery to show hide div on mouse over

Posted on 2011-03-22
4
Medium Priority
?
853 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
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 position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
Suggested Courses

777 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