title: Display line by line of file in HTML using javascript
body: <p>How can I read a file line by line in javascript and display each line in a different HTML tag? For example I want to store each line of the file in the a different <code>&lt;li&gt;</code> tag.</p>
  
  <p>This is what I've tried so far, but it just displays the entire file as a whole. I want each line in a different tag:</p>
  
  <pre><code> &lt;embed src="C://whatever.txt"&gt;
  </code></pre>
  
  <p>Also tried code below but puts everything on the same line and not in different <code>&lt;li&gt;</code> tags but just in one:</p>
  
  <pre><code>    window.onload = function() {
      var ul = document.getElementsByTagName('ul')[0];
  
      function readTextfile() {
          var xhr = new XMLHttpRequest();
  
          xhr.onreadystatechange = function() {
              if (xhr.readyState === 4) {
                  if (xhr.status == 200) {
                      showContents(xhr.responseText, xhr);
                  }
              }
          }
  
          xhr.open('GET', "C://whatever.txt", true);
          xhr.send();
      }
  
      function showContents(responseText) {
          var li = document.createElement('li');
          var date = new Date();
          li.innerHTML = date + ': ' + responseText;
          ul.appendChild(li);
      }
  
      readTextfile();
  </code></pre>