1

Trying to list the event listeners on a website with the following code:

$( document ).ready(function() {
    var s = $._data($('.group4.cboxElement')[0], "events")
    console.log(s);
  });

However getting Undefined on the console.log() line.

This is the website, I need to see what event listeners are attached to the <a> links in the Gallery tab.

Edit: Can someone tell me how to listen the events attached, or remove them that would be great.

Browser: Chrome

Martyn Ball
  • 4,679
  • 8
  • 56
  • 126
  • 1
    I can't find anything called `_data` in the jQuery API. My guess is that it is a custom function or third-party plugin. – Álvaro González Dec 01 '16 at 16:34
  • Using Google Chrome, console.log usually works fine. @ÁlvaroGonzález in that case how do I list the event listeners attached to an object? – Martyn Ball Dec 01 '16 at 16:36
  • 1
    @ÁlvaroGonzález That's a non public jQuery method (internal). It can change from version to version – A. Wolff Dec 01 '16 at 16:37
  • Well yes, i'm attempting to figure out what event listener is attached to an object, or remove it. Clearly my code is incorrect. – Martyn Ball Dec 01 '16 at 16:38
  • using jQuery: 1.7.1 – Martyn Ball Dec 01 '16 at 16:40
  • 2
    `jQuery( elem ).data( "events" );` < version 1.8, also check here: http://stackoverflow.com/questions/2518421/jquery-find-events-handlers-registered-with-an-object – Syden Dec 01 '16 at 16:41

1 Answers1

4

There's no official API for doing this.

If your goal is just to do this as part of debugging, Chrome itself can show you the event listeners attached to an element at the DOM level, see this question and its answers, and there are Chrome extensions (like this one) that can show you the jQuery event handlers as well (since jQuery maintains its own list of handlers, using only a single handler per event per element).

Community
  • 1
  • 1
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875