0

I need to upgrade jQuery from 1.11.1 to 3.5.1 and in some of the codebase I found .hover(function(){}, funtion(){}) being implemented.

I wonder if this is deprecated and won't work in future version of jQuery? I have checked if it works in latest version and it works as expected but found that

$(element).on('hover', function(){
     $(this).addClass('abc');
})

doesn't work. I have gone through some SO QA and found that instead need to use mouseenter and mouseleve

$(element).on('mouseenter', function(){
    $(this).addClass('abc');
}).on('mouseleave', function(){
    $(this).removeClass('abc');
});

Also is it recommended to use .on(.....) method in latest version of jQuery instead of using .hover(....)?

So can you point me if I can leave .hover(function(){}, function(){}) as it is or should I rewrite it to .on('mouseenter', function(){}).on('mouseleave', function(){})

Bhuban Shrestha
  • 1,304
  • 11
  • 27
  • https://stackoverflow.com/questions/9827095/is-it-possible-to-use-jquery-on-and-hover – epascarello Oct 22 '20 at 14:59
  • Jquery has some shortcuts for events, eg `$().click(()=>` is the same as `$().on("click", ()=>` - but `hover` is **not an event** - `$().hover(..)` is *not* a shortcut for `$().on("hover",..` – freedomn-m Oct 22 '20 at 15:22

0 Answers0