title: Attach event handlers for click event on all elements in the DOM
body: <p>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 use something like jQuery delegate.</p>
  <p>One way to do this is to iterate through all elements in the DOM and then attach an event handler to each element - but this will be slow and complicated - every time new html is dynamically added, I'd have to either re-attach all the handlers, or figure out the subset of html that was added.</p>
  <p>The other way is to use event bubbling - so add an event handler to the document, or body and rely upon the events bubbling up.</p>
  <p>Something like this:</p>
  <pre><code>$('body').delegate('div', 'click', function(e){
      dummyId++;
      console.log(e);
      console.log(e.currentTarget);
      console.log(&quot;=====&quot;);
  
  });
  </code></pre>
  <p>However, after using this code, when I click on buttons on my page, I get the div surrounding the button, as opposed to the actual button. In other words, the above is too specific. Furthermore, I feel like the original selector should be the document, rather than the body tag.</p>
  <p>To be clear, I want to know when any element is clicked on my page - how do I do that?</p>
  <p>So I tried this code with <code>.on</code>:</p>
  <pre><code>$(document).on('click', function(e){
      console.log(&quot;EVENT DUMMY ID&quot;);
  
      console.log(e.target);
      console.log(&quot;=====&quot;);
  
  });
  </code></pre>
  <p>However, when I click on buttons in my app, nothing gets triggered - when I click on other elements, the console logs run.</p>
  <p>I understand this is probably hard to answer without more context - what else do you need?</p>