How to use .removeClass() to disable jquery function

无人久伴 提交于 2019-12-22 18:19:50

问题


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.

I am using the following code.

//Click this 
$('button').click(function() {
    $('#main-div').removeClass('hover-on');
});

//Remove class to disable this hover function
$('.hover-on').hover(function() {
    blah blah blah
});

回答1:


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


来源:https://stackoverflow.com/questions/6338723/how-to-use-removeclass-to-disable-jquery-function

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