title: Alternative way to use JavaScript to write to a <div> element?
body: <p>I want to print out a message in the page's <code>&lt;div&gt;</code> element upon page load. I have the following HTML and JavaScript code:</p>
  
  <pre><code>&lt;body onload="printMsg()"&gt;
      &lt;div id="write"&gt;&lt;/div&gt;
  &lt;/body&gt;
  
  function printMsg() {
      var node = document.getElementById("write");
      node.innerHTML = "&lt;p&gt;" + "Hello World!" + "&lt;/p&gt;";
  }
  </code></pre>
  
  <p>Here I used <code>onload</code> event in <code>&lt;body&gt;</code> element to call <code>printMsg()</code> upon page load. </p>
  
  <p>But if I don't use <code>onload</code> event, is there any alternative way to write to <code>&lt;div id="write"&gt;&lt;/div&gt;</code> directly within the JavaScript function <code>printMsg()</code>?</p>