title: Wait for jquery .html method to finish rendering
body: <p>I have div with vertical scroll bar. Div is being updated dynamically via ajax and html is inserted using jQuery's .html method.
  After div is updated scroll bar returns to top and I am trying to keep it in the previous position.</p>
  
  <p>This is how I'm trying it:</p>
  
  <pre><code>var scrollPos = $('div#some_id').scrollTop(); //remember scroll pos
  $.ajax({...
      success: function(data) {
          $('div#some_id').html(data.html_content); //insert html content
          $('div#some_id').scrollTop(scrollPos); //restore scroll pos
      }
  });
  </code></pre>
  
  <p>This fails. My best guess is that it is failing due to inserted html not rendered (ie. no scroll).</p>
  
  <p>For example this works.</p>
  
  <pre><code>setTimeout(function(){
      $('div#some_id').scrollTop(scrollPos);
  }, 200);
  </code></pre>
  
  <p>But this is dirty hack in my opinion. I have no way of knowing that some browsers won't take more then these 200ms to render inserted content.</p>
  
  <p>Is there a way to wait for browser to finish rendering inserted html before continuing ?</p>