What's wrong with my jquery hover show function?

I have a div that is set to display:none. When I hover over an element I want it to show that div.

My scripts below didn't work.
<!-- test 1 -->
<script type="text/javascript">
   $(".topMain").hover(function(){
      $("#topHoverMenu").show();
   });
</script>
 
<!-- test 2 -->
<script type="text/javascript">
   $(".topMain").hover(function(){
      $("#topHoverMenu").css(display: 'block');
   });
</script>

Open in new window

LVL 1
Shaye LarsenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chad HaneyChief Technology OfficerCommented:
Where are you calling that script?  If you are calling it in the head and not with an on document ready then you are having the jquery try to set the hover function to an element that doesn't exist.

You could also put the code you have after the elements, but this wouldn't be the best practice.
$(function(){
 $(".topMain").hover(function(){
      $("#topHoverMenu").show();
   });
});

Open in new window

0
Shaye LarsenAuthor Commented:
Alright, thanks. I had tried it with

$(document).ready(function(){

but I must have had something off. It now works but I thought it would only show during hover, how do I get it to hide when the hover is removed?
0
Chad HaneyChief Technology OfficerCommented:
Just put a comma, and add the function you want to call on the hover out.
$(function(){
 $(".topMain").hover(function(){
      $("#topHoverMenu").show();
   },function(){
      $("#topHoverMenu").hide();
   });
});

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Shaye LarsenAuthor Commented:
Nevermind I got it. Thanks!

Here is the completed script:
$(function() {
   $(".topMain, #topHoverMenu").hover(function() {
      $("#topHoverMenu").show().stop().animate({top:"-27px"}, 375);//you can change "#helpPanel" on this line to 'this' (without single quotes) if you don't use #helpOpen on the line above
   },
   function() {
      $("#topHoverMenu").hide().stop().animate({top:"0px"}, 800);
   });
});

Open in new window

0
Shaye LarsenAuthor Commented:
Perfect! A definite genius!!!
0
Chad HaneyChief Technology OfficerCommented:
No Problem
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.