List all live events in jQuery

后端 未结 3 642
醉酒成梦
醉酒成梦 2021-02-15 15:52

How could I find in jQuery what events are bound with live for a particular element?

Say I have a function, randomFunction, that returns a random function f

相关标签:
3条回答
  • 2021-02-15 16:12

    Take a look at this plugin. When I last used this, there was a need to slightly modify it for the then latest version of jQuery, but it should give you a direction.

    0 讨论(0)
  • 2021-02-15 16:26

    There's a nifty bookmarklet called Visual Event that shows the code that will be called.

    But since you're truly calling a random function, maybe doing something as simple as including an alert("function name") or colsone.log("function"), if you're just testing.

    0 讨论(0)
  • 2021-02-15 16:31

    Alright, figured it out. For a click event, for $('#certain_element'), logging each binding's index to the console:

    var relevantHandlers = $.map($(document).data('events').live, function(value){
      if(value.origType == 'click' && value.selector == '#certain_element'){
        return value.handler;
      }
    }; //all handlers for #certain_element bound to click by live.
    $.each(relevantHandlers, function(){
      console.log("the index is: " + $.inArray(this, arrayOfFunctions));
    });
    
    0 讨论(0)
提交回复
热议问题