How do I unbind “hover” in jQuery?

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

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

This does not work:

$(this).unbind(\'hover\');
8条回答
  •  無奈伤痛
    2020-11-28 03:43

    I found this works as second argument (function) to .hover()

    $('#yourId').hover(
        function(){
            // Your code goes here
        },
        function(){
            $(this).unbind()
        }
    });
    

    The first function (argument to .hover()) is mouseover and will execute your code. The second argument is mouseout which will unbind the hover event from #yourId. Your code will be executed only once.

提交回复
热议问题