title: How to wait for an execution to finish before doing next line
body: <p>The title say it all.
  I've found some answers(about callback and something else) but I don't know how to apply it to my code.</p>
  
  <p><strong>Question :</strong> how to wait for <code>$( "#layout-grid" ).load(layout);</code> finished before executing next line ?</p>
  
  <p>The alert at the last line won't show up on the first execution because <code>$( "#layout-grid" ).load(layout);</code> is not finished loading yet. However, the alert shows correctly on the second execution.</p>
  
  <pre><code>function setLayout(selectedLayout) {
      layout += selectedLayout;
      $( "#layout-grid" ).load(layout); // this load is not finished yet before alert
      var top_level_div = document.getElementById('layout');
      var count = top_level_div.getElementsByTagName('div').length;
      alert(count);
  }
  </code></pre>