How do I unbind “hover” in jQuery?

前端 未结 8 2011
醉话见心
醉话见心 2020-11-28 02:54

How do I unbind \"hover\" in jQuery?

This does not work:

$(this).unbind(\'hover\');
8条回答
  •  被撕碎了的回忆
    2020-11-28 03:33

    You can remove a specific event handler that was attached by on, using off

    $("#ID").on ("eventName", additionalCss, handlerFunction);
    
    // to remove the specific handler
    $("#ID").off ("eventName", additionalCss, handlerFunction);
    

    Using this, you will remove only handlerFunction
    Another good practice, is to set a nameSpace for multiple attached events

    $("#ID").on ("eventName1.nameSpace", additionalCss, handlerFunction1);
    $("#ID").on ("eventName2.nameSpace", additionalCss, handlerFunction2);
    // ...
    $("#ID").on ("eventNameN.nameSpace", additionalCss, handlerFunctionN);
    
    // and to remove handlerFunction from 1 to N, just use this
    $("#ID").off(".nameSpace");
    

提交回复
热议问题