title: Bind event to dynamically created HTML elements with vanilla JavaScript [no jquery]
body: <p>I need to attach an event to a dynamically created element. With jQuery I can archive this by using the following code:</p>
  
  <pre><code>$("body").on("click", ".my-element", function() {});
  </code></pre>
  
  <p>And if I added a new <code>.my-element</code>, it automatically got the event attached.</p>
  
  <p>I'm not creating the elements via <code>document.createElement("div");</code>, but I'm using <a href="https://github.com/MoOx/pjax" rel="nofollow noreferrer">pjax</a> to reload just some parts of the page, so the main JavaScript file just loads one time, for that reason events need to be attached dynamically.</p>
  
  <p>How can I achieve that with vanilla JavaScript?</p>