title: jQuery loading window while waiting for long function to finish
body: <p>I'm trying to adapt this solution to my needs: <a href="https://stackoverflow.com/questions/1964839/jquery-please-wait-loading-animation">How can I create a &quot;Please Wait, Loading...&quot; animation using jQuery?</a></p>
  
  <p>Basically a really awesome scheme is provided to wrap Ajax requests with a nice loading GUI. I'm trying to do the same for a function I have that does some calculations and then appends some graphics to the DOM. </p>
  
  <p>So what I've tried is this: </p>
  
  <pre><code>$("body").addClass("loading");
  long_time_taking_function(mainDiv);
  $("body").removeClass("loading");
  </code></pre>
  
  <p>Unfortunately it appears as though the class is added and then removed instantly, either before or after the long_time_taking_function() executes. However I know that adding the class works, because commenting out the removeClass() call keeps the gif floating on the page. </p>
  
  <p>Any ideas how I can make this work? I can provide more details about the intermediate function if needed. </p>
  
  <p>Cheers</p>