jQuery .hover not working

21,759

Solution 1

Try fixing your function like below,

$(function() {        
    $('#open').hover(function(){ //Open on hover 
        $('#pull_down_content').animate({'top':'-0px'},1000);
    },    
    function(){ //Close when not hovered
        $('#pull_down_content').animate({'top':'-340px'},1000);    
    });
});

Solution 2

Just need a little fix

$('yourElement').hover(
   function(){
      // hover code
   }, function(){
      // unhover code 
   }
);
Share:
21,759
Ben Jackson
Author by

Ben Jackson

Updated on June 22, 2020

Comments

  • Ben Jackson
    Ben Jackson about 4 years

    Hi What is wrong with my code here:

    When I hover over #open #pull_down_content should be moving down the page from the header and when I move away from #open it should move back up. But when I test the code as soon as the page loads #pull_down_content moves down the screen before I even hover over it.

    $(function() {
    
    //Open on hover 
    $('#open').hover((function(){
        $('#pull_down_content').animate({'top':'-0px'},1000);
    })
    
    //Close when not hovered
    (function(){
        $('#pull_down_content').animate({'top':'-340px'},1000);
    
    })
    });
    );