6. Hover


#1



https://www.codecademy.com/courses/web-beginner-en-JwhI1/1/2?curriculum_id=50a3fad8c7a770b5fd0007a1#


When running my code, it works perfectly, but for some odd reason, it won't allow me to pass. I also receive the following error "Oops, try again. It doesn't look like your background changed back, did you remove the active class?" Can someone explain what I'm doing wrong and/or how to fix said problem? Thanks in advance, here is my code:


$(document).ready(function(){

  $('div').hover(
    function(){
        $(this).addClass('active');
    },
    function(){
        $('div').mouseleave(function() {
            $(this).removeClass('active');
        });
    }
  );

});


#2

After looking at my code and others, I realized that the mouseleave function was unnecessary, and upon removing it, the code worked perfectly.
$(document).ready(function(){

  $('div').hover(
function(){
 $(this).addClass('active');
},
function(){
 $(this).removeClass('active');   
}
);

});

#3

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.