List of Events Attached
jQuery events that is
by dbjdbj
HTML
<div>I am a single DIV</div>
CSS
html,body { font-size:24px; }
JavaScript
function print (s) {
setTimeout(function () { document.body.innerHTML += "<li>"+s+"</li>" ; }, 1 ) ;
};
/*
(c) 2015 by DBJ.ORG, GPL/MIT applies
expr argument is any legal jQuery selector.
returns array of { element: , events: } objects
events: is jQuery events structure attached (as data)
to the element:
return is null if no events are found
*/
jQuery.events = function (expr ) {
var rez = [], evo ;
jQuery(expr).each(
function () {
if ( evo = jQuery._data( this, "events"))
rez.push({ element: this, events: evo }) ;
});
return rez.length > 0 ? rez : null ;
}
/*
first attach the click event to some lonely single div in your html
*/
$("div").click ( function (Evt) { /* event handler */ } ) ;
/*
elsewhere we can get the list of events we or anybody else has attached to the div
*/
var event_list = jQuery.events("div") ;
print(event_list[0].events.click[0].handler);