title: How to make autoscrolling on if in javascript
body: <p>I made a chat in PHP/JS/JQuery and I want autoscroll after new message appears. Here's my code(javascript):</p>
  
  <pre><code>$(function(){
  $(document).on('submit','#chatForm',function(){
      var text = $.trim($("#text").val());
      var name = $.trim($("#name").val());
  
      if(text != "" &amp;&amp; name != ""){
          $.post('poster.php',{text: text, name: name},function(data){
              $(".chatMessages").append(data);
          });
      }else{
          alert("Data missing!");
      }
  });
  
  function getMessages(){
      $.get('receive.php',function(data){
          $(".chatMessages").html(data);
      });
  }
  
  setInterval(function(){
      getMessages();
      document.getElementById( 'chatBottom' ).scrollIntoView();
  },500);
  });
  </code></pre>
  
  <p>But it does not scroll</p>