Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jquery

unbind

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?

like image 322
Aximili Avatar asked Apr 28 '10 07:04

Aximili


2 Answers

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.

like image 75
rahul Avatar answered Nov 01 '22 10:11

rahul


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();
like image 24
Felix Kling Avatar answered Nov 01 '22 10:11

Felix Kling