18 июн. 2013 г.

Find jQuery events on specific element

$._data($element[0], 'events');
will return all event handlers

$._data($element[0]);
will return all jQuery data (set by $(element).data(key, value)) and event handlers (set by $(element).on(eventName, handler)) for this element

Example in Chrome's console:

> $._data($('body')[0])
Object {events: Object, handle: function, data: Object}

  • data: Object
    uiProgressIndicator: $.(anonymous function).(anonymous function)
    __proto__: Object
  • events: Object
    click: Array[3]
    remove: Array[1]
    __proto__: Object
  • handle: function ( e ) {
    arguments: null
    caller: null
    elem: body
    length: 1
    name: ""
    prototype: Object
    __proto__: function Empty() {}
    <function scope>
  • __proto__: Object

We can see data for jQuery UI widget named 'progressIndicator' and four event handlers (three for 'click', one for 'remove' event) attached to the body of the HTML document.

Also Chrome has built-in command getEventListeners to show DOM event handlers attached to element:

> getEventListeners(document.body)
Object {click: Array[1], remove: Array[1]}

  • click: Array[1]
  • remove: Array[1]
  • __proto__: Object