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

跟風遠走 提交于 2019-12-12 10:36:51

问题


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?


回答1:


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.




回答2:


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



回答3:


Try this:

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



回答4:


.hover is a wrapper for mouseenter and mouseleave.

Try calling unbind on those.



来源:https://stackoverflow.com/questions/2727570/jquery-unbindhover-does-not-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!