title: Adding custom CSS classes to dynamically-created elements with jQuery
body: <p>Let me illustrate my question: I have an external JavaScript library that creates certain HTML elements for me dynamically based on user input and interaction, and I'm looking to write a script that would automatically add a certain class to these dynamically created elements. Assume that I also am unable to edit the external JavaScript library I'm using.</p>
  
  <p>Is this elegantly possible? If so, how? If not, could this be a side-effect of poor implementation design?</p>
  
  <p>I've thought about somehow monitoring the DOM to see when it was updated, and adding the classes to these new elements then, but this seems cumbersome and possibly unnecessary.</p>
  
  <p>Thanks in advance for any thoughts / solutions!</p>
  
  <p><em><strong>Edit:</em></strong></p>
  
  <p>As requested, here's a simplified example of what I'm trying to accomplish with a code sample:</p>
  
  <pre><code>// function in external library, assume it cannot be edited!
  function addElement() {
      $('body').append($('&lt;div class="newly_created_element"&gt;&lt;/div&gt;'));
  }
  
  // my code, looking to add the class name to the newly-created elements
  // from the external function above...
  // pseudo-coded as I have no idea how to do this!
  $(function(){
      when (new element added) {
          add class "my_own_class";
      }
  });
  </code></pre>
  
  <p>I hope this makes sense!</p>