jQuery find events handlers registered with an object

后端 未结 16 3132
予麋鹿
予麋鹿 2020-11-21 07:16

I need to find which event handlers are registered over an object.

For example:

$(\"#el\").click(function() {...});
$(\"#el\").mouseover(function() {         


        
16条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-21 08:06

    Another way to do it is to just use jQuery to grab the element, then go through actual Javascript to get and set and play with the event handlers. For instance:

    var oldEventHandler = $('#element')[0].onclick;
    // Remove event handler
    $('#element')[0].onclick = null;
    // Switch it back
    $('#element')[0].onclick = oldEventHandler;
    

提交回复
热议问题