jQuery unbind('hover') does not work [duplicate]
Asked Answered
L

4

8

My unbind does not work.

$("img.hoverable").hover(ChangeImage, ChangeBack);
$("a img.hoverable").unbind('hover');

The HTML could be like this

<img class="hoverable" src="something.jpg"/>
<a href="#"><img class="hoverable" src="something.jpg"/></a>

When I hover over the second HTML, ChangeImage is still fired.

I am not sure if I am using it correctly, can anyone please advise?

Lordsandladies answered 28/4, 2010 at 7:37 Comment(0)
Z
15

Try

$("img.hoverable").unbind('mouseenter mouseleave');

The .hover() method binds handlers for both mouseenter and mouseleave events. So inorder to unbind you will have to unbind mouseenter and mouseleave.

Zagazig answered 28/4, 2010 at 7:42 Comment(1)
This doesn't work when I try itDumah
W
5

hover is a pseudo event for mouseenter and mouseleave. So you have to unbind these.
Or if no other handler is attached, call .unbind() without parameters (removes any handler).

$("a img.hoverable").unbind();
Whisenant answered 28/4, 2010 at 7:42 Comment(0)
A
0

Try this:

$("img.hoverable").hover(ChangeImage, ChangeBack);
$("img.hoverable").unbind('hover');
Absa answered 28/4, 2010 at 7:41 Comment(0)
N
0

.hover is a wrapper for mouseenter and mouseleave.

Try calling unbind on those.

National answered 28/4, 2010 at 7:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.