如何使用.removeClass()禁用jQuery功能 [英] How to use .removeClass() to disable jquery function
本文介绍了如何使用.removeClass()禁用jQuery功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望单击按钮以删除类"hover-on",以便禁用悬停功能,但是一旦DOM加载,它便删除了该类,但悬停功能仍然有效.
I want the button click to remove the class "hover-on" so that the hover function becomes disabled, but once the DOM loads it removes the class, but the hover function still works.
我正在使用以下代码.
//Click this
$('button').click(function() {
$('#main-div').removeClass('hover-on');
});
//Remove class to disable this hover function
$('.hover-on').hover(function() {
blah blah blah
});
推荐答案
该事件与CSS类无关.您需要取消绑定该事件:
The event doesn't have anything with the CSS class. You need to unbind the event:
$('button').click(function() {
$('#main-div').removeClass('hover-on').unbind("hover");
});
$('.hover-on').hover(function() {
blah blah blah
});
这篇关于如何使用.removeClass()禁用jQuery功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文