开发者

How can I get information about events that are bound to an element via live()?

开发者 https://www.devze.com 2023-04-13 06:18 出处:网络
I have one <a> tag and bind to it two events.How I can get information about other events attached to it?

I have one <a> tag and bind to it two events. How I can get information about other events attached to it?

The follow code explains what I mean:

<a href="#" id="sample" class="sample-cls">Click me</a>

$(function(){
    $('#sample').live("click", function(){
        sampleFunction();
    })
    $('.sample-cls')开发者_开发百科.live("click", function(){
        // How to get information that to this link 
        // is attached another event, that run sampleFunction() ?
    })
})

Unfortunately, $('#sample').data('events') doesn't include the events bound via live().


// List bound events:
console.dir( jQuery('#elem').data('events') );

// Log ALL handlers for ALL events:
jQuery.each($('#elem').data('events'), function(i, event){
    jQuery.each(event, function(i, handler){
        console.log( handler.toString() );
    });
});

See this

Of course, this can be further enhanced to suit your needs.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号