6. Why are we adding opposite effects to the same handler?


#1


So on exercise 6, "jQuery events, Hover", we add the exact opposite effects to the div (addClass and removeClass) within the same event handler (hover). How does this work? Surely if you hover, it would apply one of the effects, not both?


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


Exercise example : 

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


#2

no, the .hover is smart, it will see that there are two functions to this event, it will execute the first function for mouseenter and execute the second function on mouseleave


#3

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