Best way to get the Original Target

后端 未结 5 547
孤街浪徒
孤街浪徒 2020-12-05 17:53

What\'s a jQuery like and/or best practices way of getting the original target of an event in jQuery (or in browser javascript in general).

I\'ve been using someth

5条回答
  •  借酒劲吻你
    2020-12-05 18:36

    I believe e.target is what you require

    $('body').bind('click', function(e){
                    e.target // the original target
                    e.target.id // the id of the original target                                               
    });
    

    If you go to the jQuery in Action website and download the source code, take a look at

    • Chapter 4 - dom.2.propagation.html

    which deals with event propagation with bubble and capture handlers

提交回复
热议问题