How to access jquery internal data?

As you may or may not know about jQuery 1.7, the entire event system has been rewritten from scratch. The codebase is much faster, and with the new .on () method, there is a lot of uniformity for posting event handlers.

One of them was used to access the data of internal events and to check which events were registered in any element, but recently this internal information has been hidden based on the following scenario ...

It seems that the "private" data is ALWAYS stored in .data (jQuery.expando). For “objects,” where deleting an object should also delete its caches, this makes sense.

In the area of ​​nodes, however, I think we should store these "private" members in a separate (private) cache so that they do not pollute the object returned by $ .fn.data () "

Although I agree with the above change in order to hide internal data, I found that access to this information may be useful for debugging and unit testing.

What is the new way to get the internal jquery event object in jQuery 1.7?

+5
source share
1 answer

jQuery 1.7 , $._data() ( , , ).

, , $._data() events . :

$("#yourElement").click(function() {
    // ...
});

console.log($._data($("#yourElement")[0]).events);
+3

All Articles