开发者

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

开发者 https://www.devze.com 2022-12-28 05:10 出处:网络
This question already has answers here: 开发者_如何学编程 How do I unbind "hover" in jQuery?
This question already has answers here: 开发者_如何学编程 How do I unbind "hover" in jQuery? (8 answers) Closed 7 years ago.

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?


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.


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();


Try this:

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


.hover is a wrapper for mouseenter and mouseleave.

Try calling unbind on those.

0

精彩评论

暂无评论...
验证码 换一张
取 消