Friday 18 January 2019

jQuery find events handlers registered with an object



I need to find which event handlers are registered over an object.



For example:




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


$("#el") has click and mouseover registered.



Is there a function to find out that, and possibly iterate over the event handlers?



If it is not possible on a jQuery object through proper methods, is it possible on a plain DOM object?



Answer



As of jQuery 1.8, the event data is no longer available from the "public API" for data. Read this jQuery blog post. You should now use this instead:



jQuery._data( elem, "events" );


elem should be an HTML Element, not a jQuery object, or selector.



Please note, that this is an internal, 'private' structure, and shouldn't be modified. Use this for debugging purposes only.




In older versions of jQuery, you might have to use the old method which is:



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

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...