Capture all events (click, change, onmouseover, e.t.c) for a given element using jquery
Is there anyway that I can check if an existing element has event handlers attached to it? Suppose a simple javascript method adds a click event to some div.example (sans jquery), so there are not attribute tags, is it possible to then, using jquery, to capture the event that was attached? I tried to accomplish this using the code below to no avail:
$( '.example' ).each( function() {
var newObj = $(this);
$.each($(newObj).data("events"), function(i, event) {
alert(i);
$开发者_如何学运维.each(event, function(j, h) {
alert(h.handler);
});
});
});
Try this
$( '#elm1' ).each( function() {
$.each($(this).data("events"), function(i, event) {
alert(i);
$.each(event, function(j, h) {
alert(h.handler);
});
});
});
精彩评论