title: Iterate after ajax completes
body: <p>So I foreach 366 jquery elements and if I find a specific class I call a function, the function either loads HTML via ajax or edits already existing one. But while iterating the function just keeps loading HTML instead of editing existing one, because the ajax takes time to load it. I tried promises but I can't tell the loop to wait and then iterate.</p>
  
  <p>Basically I have</p>
  
  <pre><code>$('#calendars .day').each(function(index, element){
      if ($(element).hasClass('something')) {
          callAjaxFunction($(element).text(), $(element).data('id'));
      } else {
          callNoAjaxFunction($(element).attr('class'));
      }
  });
  </code></pre>