title: Auto typer with cursor Javascript
body: <p>I basically want to create a simple Javascript auto writer in a HTML page
  This is my code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;
  
  &lt;head&gt;
    &lt;style&gt;
      #type {
        display: inline-block;
      }
      
      #cur {
        display: inline-block;
      }
    &lt;/style&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
    &lt;pre&gt;
  &lt;div id="type"&gt;&lt;/div&gt;&lt;div id="cur"&gt;{cursor}&lt;/div&gt;
  &lt;/pre&gt;
    &lt;script&gt;
      var string = "Write this string!\nNext Line!";
      var array = string.split("");
      var timer;
  
      function looper() {
        if (array.length &gt; 0) {
          document.getElementById("type").innerHTML += array.shift();
        } else {
          clearTimeout(looper);
        }
        timer = setTimeout('looper()', 50);
      }
      looper();
    &lt;/script&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>The string "{cursor}" should be the cursor position, I will create it later.
  The problem with it is when I go to a new line; Essentially the cursor not returns to initial position on the line but remains to the last position it took doing just a "jump" to the next line.</p>