title: jQuery timing - wanting to add something akin to DoEvents() in a method
body: <p>I have a table of data that contains about 260 rows.  Each of these rows is identified by an attribute such as parentHeaderName.  When the header of that table is clicked, I have some jQuery in place that briefly changes the header to an ajaxload.gif image, like this</p>
  
  <pre><code>$('#Header').html('&lt;img src="images/ajaxload.gif"');
  </code></pre>
  
  <p>and then I toggle all 260 rows by calling</p>
  
  <pre><code>$([parentHeaderName=something]).toggle();
  </code></pre>
  
  <p>Unfortunately, I am not able to get the part of my code that changes the header to the ajaxload.gif to run properly.  It is as though both that statement, and the toggle statement, are running all at the same time.  Meaning, that the user never sees the ajaxload.gif.  The only way I can get the image to show is if I put an alert('...') message between the two statements.  Obviously, this is not desired as a solution.  I've tried using delay() and setTimeout to no avail.  I guess what I need is some sort of DoEvents equivalent in jQuery or javascript that would let the image show prior to the toggle execution.</p>
  
  <p>Any ideas?</p>
  
  <p>Thanks,
  Chris</p>
  
  <p>UPDATE:  Thanks for the feedback folks.  Here's the actual code:</p>
  
  <pre><code>$('.sixdegreestypeheader').click(function() {
      var headerName = $(this).attr("headername");
      var jq = "[headername$=" + headerName + "]";
      var jq2 = "[parentheadername$=" + headerName + "]";
  
      var originalTextValue = $(jq).text();
      var originalHTMLValue = $(jq).html();
  
      if (originalHTMLValue.indexOf("collapse") == -1) {
          $(jq).html('&lt;img src="images/collapse.gif" /&gt; ' + originalTextValue);
      }
      else {
          $(jq).html('&lt;img src="images/expand.gif" /&gt; ' + originalTextValue);
      }
  
      // alert('break here to act as a DoEvents.') // this forces the image change... but I don't want to have to use an alert to force this
      $(jq2).toggle();
  
      return false;
  });
  </code></pre>
  
  <p>(This code actually changes the header to expand.gif or collapse.gif, rather than ajaxload.gif.)</p>
  
  <p>I did try the delay suggestion </p>
  
  <pre><code>$(jq2).delay(500).toggle();
  </code></pre>
  
  <p>but it did not help any.  When the number of rows that need to get toggled is small - say, up to about 20 - there is no problem.  But in some cases, I need to hide a bunch (e.g. 260), and it is as though the browser needs several seconds to chug through the DOM to do all of its hiding of things.  That's why I was originally hoping to use the ajaxload.gif image.</p>
  
  <p>Thanks,
  Chris</p>