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?

Aximili
  • 28,626
  • 56
  • 157
  • 216

4 Answers4

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.

rahul
  • 184,426
  • 49
  • 232
  • 263
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();
Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
0

Try this:

$("img.hoverable").hover(ChangeImage, ChangeBack);
$("img.hoverable").unbind('hover');
Krunal
  • 3,443
  • 3
  • 23
  • 27
0

.hover is a wrapper for mouseenter and mouseleave.

Try calling unbind on those.

Francisco Soto
  • 10,277
  • 2
  • 37
  • 46