I am looking for a way to watch for dynamically populated (no page reload) content inside an element so that I can add a class to another element.
I have this so far:
HTML<div class="message-container">
  <div class="messages error"><span></span></div>
  <div class="messages success"><span></span></div>
  <div class="messages warning"><span></span></div>
  <div class="messages warning"><span></span></div>
</div>
<div class="myDiv">...</div>
$(document).ready(function() {
  if($.trim($("div.messages.success span").html()) != '') {
    $('.myDiv').addClass('.with-message');
  }
});
How can I have myDiv to have the with-message class when any message span is populated? 
Note it ay be populated on the fly without reloading, or exist when landing on the page, or be populated with a reload.
 
     
     
     
     
    