I need to find which event handlers are written on the object.

For example:

$("#el").click(function() {...}); $("#el").mouseover(function() {...}); 

On $("#el") , click and mouseover events are recorded.

Is there a function to find out, and is it possible to iterate over event handlers?

If this is not possible in the jQuery object using the correct methods, is it possible for a regular DOM object?

Translated from: https://stackoverflow.com/questions/2518421/

1 answer 1

Beginning with jQuery 1.8, event information is no longer available from the public API for data. Read this jQuery blog post . Now, in order to find out the list of events recorded on the object, you need to use this:

 jQuery._data( elem, "events" ); 

The elem must be an HTML element, not a jQuery object or selector.

Please note that this is an internal, “private” structure and should not be changed. Use it only for debugging purposes.

In older versions of jQuery, you may need to use the old method:

 jQuery( elem ).data( "events" ); 

Example:

 $('#el').click(function() { $(this).text('Нажали!'); }) $('#el').mouseover(function() { $(this).text('Поводили мышкой!'); }); // Получаем события var elem = $('#el').get(0); console.log( $._data(elem, "events") ); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <div id="el">Текст</div>