Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I unbind "hover" in jQuery?

How do I unbind "hover" in jQuery?

This does not work:

$(this).unbind('hover'); 
like image 657
zsharp Avatar asked Apr 30 '09 02:04

zsharp


People also ask

How do I get rid of hover?

To remove the CSS hover effect from a specific element, you can set the pointer-events property of the element (the hover behavior of which you want to disable) to “none”.

Is hover deprecated in jQuery?

hover() is deprecated #66.

How to use hover function in jQuery?

jQuery hover() MethodThe hover() method specifies two functions to run when the mouse pointer hovers over the selected elements. This method triggers both the mouseenter and mouseleave events. Note: If only one function is specified, it will be run for both the mouseenter and mouseleave events.

What is the jQuery equivalent of Onmouseover?

jQuery mouseover() Method Note: Unlike the mouseenter event, the mouseover event triggers if a mouse pointer enters any child elements as well as the selected element. The mouseenter event is only triggered when the mouse pointer enters the selected element. See the example at the end of the page for a demonstration.


2 Answers

$(this).unbind('mouseenter').unbind('mouseleave')

or more succinctly (thanks @Chad Grant):

$(this).unbind('mouseenter mouseleave')

like image 69
Crescent Fresh Avatar answered Sep 24 '22 06:09

Crescent Fresh


Actually, the jQuery documentation has a more simple approach than the chained examples shown above (although they'll work just fine):

$("#myElement").unbind('mouseenter mouseleave'); 

As of jQuery 1.7, you are also able use $.on() and $.off() for event binding, so to unbind the hover event, you would use the simpler and tidier:

$('#myElement').off('hover'); 

The pseudo-event-name "hover" is used as a shorthand for "mouseenter mouseleave" but was handled differently in earlier jQuery versions; requiring you to expressly remove each of the literal event names. Using $.off() now allows you to drop both mouse events using the same shorthand.

Edit 2016:

Still a popular question so it's worth drawing attention to @Dennis98's point in the comments below that in jQuery 1.9+, the "hover" event was deprecated in favour of the standard "mouseenter mouseleave" calls. So your event binding declaration should now look like this:

$('#myElement').off('mouseenter mouseleave');

like image 45
Phil.Wheeler Avatar answered Sep 21 '22 06:09

Phil.Wheeler