jQuery find events handlers registered with an object

后端 未结 16 3121
予麋鹿
予麋鹿 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 07:56

    For jQuery 1.8+, this will no longer work because the internal data is placed in a different object.

    The latest unofficial (but works in previous versions as well, at least in 1.7.2) way of doing it now is - $._data(element, "events")

    The underscore ("_") is what makes the difference here. Internally, it is calling $.data(element, name, null, true), the last (fourth) parameter is an internal one ("pvt").

提交回复
热议问题