title: JS/jQuery: When prepending a dynamic element, how to force the container div to extend upwards instead of downwards?
body: <p>If you've noticed, it seems that when <code>prepend()</code> is used, the additional elements get piled at the top but the container div is extended downwards. </p>
  
  <p>Comparing with FB's load previous message, you will notice that elements are loaded on top of each other but your <strong>view does not change</strong>. It is like <code>append()</code> except the container div "seems" to extend upwards. </p>
  
  <p><strong>I've tried doing this to <em>simulate the div extending upwards</em> but failed</strong></p>
  
  <pre><code>var scrolldif = $('#response')[0].scrollHeight-$('#response').scrollTop();
  $('#response').scrollTop(scrolldif);
  </code></pre>
  
  <p>Here is the sample html to try. Just copy/paste/run in browser.</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"&gt;
      &lt;script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="http://maxcdn.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;style type="text/css"&gt;
      .chatbox div{
          height: 100%;
      }
      #response{
          height: 300px;
          overflow-y: scroll;
          overflow-wrap: break-word;
      }
  
  &lt;/style&gt;
  &lt;script type="text/javascript"&gt;
      function appendMessage()
      {
          var data = 'test';
          var message = document.createElement('p');
          message.innerHTML = data;
          $('#response').append(message);
      }
  
      function prependMessage()
      {
              var data = 'test'+Math.floor((Math.random() * 10) + 1);
              var message = document.createElement('p');
              message.innerHTML = data;
              console.log(message.innerHTML);
              $('#response').prepend(message);
      }
  
  &lt;/script&gt;
  &lt;body&gt;
  &lt;div class="container"&gt;
      &lt;div class="chatbox"&gt;
          &lt;div class="col-sm-8 rightP"&gt;
              &lt;div class="row contents"&gt;
                  &lt;a onclick="return appendMessage()" class="load btn btn-default"&gt;Append&lt;/a&gt;
                  &lt;a onclick="return prependMessage()" class="load2 btn btn-default"&gt;Prepend&lt;/a&gt;
                  &lt;div class="row msg"&gt;
                      &lt;div id="response" class="msg form-group"&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Thank you!</p>