title: Trigger Javascript Event on Add to DOM
body: <p>Does anyone know how to trigger an event in Javascript for an element after it has been added to the DOM?</p>
  <p>The general idea is something like this:</p>
  <pre><code>var elem = document.createElement('div');
  elem.addEventListener('ON_ADD_TO_BODY', function(){console.log(elem.parentNode)});
  //... LATER ON ...
  parentElemInBody.appendChild(elem); // &lt;- Event is triggered here after append
  </code></pre>
  <p>There are some functions that shouldn't be triggered until you add the element to the DOM so it would make sense to delay execution until the element is added.</p>
  <p>Is there a way to do this without explicitly needing to call them later on or should I be doing some hack that includes a <code>setTimeout</code> and a check to see if the element has been added to the DOM yet?</p>