title: Write HTML to screen with Javascript function
body: <p>I'm very new to JavaScript and HTML I and need some help!</p>
  
  <p>I'm trying to write a table in JavaScript, that writes into the page HTML, and then importing that function to a HTML file to show the table.</p>
  
  <p>I have this in a JavaScript file</p>
  
  <pre><code>function createTable()
  {
      var table = "&lt;table&gt;";
  
      table += "&lt;tr&gt;";
      table += "&lt;th&gt;&lt;center&gt;Title&lt;/center&gt;&lt;/th&gt;";
      table += "&lt;/tr&gt;";
      table += "&lt;tr&gt;";
      table += "&lt;td&gt;&lt;center&gt; data &lt;/center&gt;&lt;/td&gt;";
      table += "&lt;/tr&gt;";
      table += "&lt;/table&gt;";
  
      document.write(table);
  
  }
  </code></pre>
  
  <p>And then I specify the src and call the function in a html file like so:</p>
  
  <pre><code>&lt;head&gt;
  &lt;script scr = "source/file.js" type=text/javascript"&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;script&gt;
          createTable()
      &lt;/script&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>Although this works, I've heard that using document.write() is a very bad practice.</p>
  
  <p>I have tried using table = <code>document.getElementById('tablePrint').innerHTML;</code> and then in the HTML file used <code>&lt;div id="tablePrint"&gt;&lt;/div&gt;</code> however my table doesn't show. I've also tried <code>document.body.appendChild(table);</code> but that doesn't work either.</p>
  
  <p>Is using <code>document.write()</code> ok? Or is their a better way to write my table to the HTML on screen.</p>