Attach event handlers for click event on all elements in the DOM

后端 未结 3 1055
春和景丽
春和景丽 2021-01-20 02:41

So I want to be able to figure out which part of my page has been clicked. There is no guarantee the elements are all on the page from the get go, which means that I need to

3条回答
  •  广开言路
    2021-01-20 03:10

    Try this:

    $(document).on('click', function(e) {
       // now use e.target here
    });
    

    You can also kill the bubbling on the click event by using e.stopPropagation()

提交回复
热议问题