1

I basically want to save state of some object to restore it later, these objects are not attached to the DOM and are not html elements, just objects in Javascript. I am not interested in a debugger/visualization tool.

But I need the actual code of the custom event listeners that are also attached to the object.

These event listeners were attached via jQuery and the functions were anonymous and provided by the user.

Is there anyway to accomplish this?

axawire
  • 198
  • 3
  • 13

1 Answers1

3

One tricky way is to use jQuery's internal function _data() to get these :

var element = document.querySelector('#its-your-thing'),
    list_of_events = $._data(element, "events");

Careful thought, I do not have information about its behavior across versions (working at least in 1.9.0)

Maen
  • 10,603
  • 3
  • 45
  • 71
  • This worked for me in testing, but I decided to work the problem a different way because of it being an internal JQuery function. – axawire Nov 03 '14 at 22:15
  • 4
    I receive undefined in jQuery 3.1.0. Any other way to get event listeners on object? – FrenkyB Dec 23 '16 at 06:09