title: Create HTML5 Canvas programmatically
body: <p>I have the following HTML code snippets</p>
  
  <pre><code>&lt;body onload="main()" &gt;
      ...
      &lt;canvas id="myId" class="myClass"&gt;&lt;/canvas&gt;
      ...
  &lt;/body&gt;
  </code></pre>
  
  <p>It works as expected. I can display the output correctly.</p>
  
  <p>I then remove</p>
  
  <pre><code>&lt;canvas id="myId" class="myClass"&gt;&lt;/canvas&gt;
  </code></pre>
  
  <p>Because I want to create it programmatically with the following JavaScript code snippet</p>
  
  <pre><code>var canvas = document.createElement("canvas");
  canvas.className  = "myClass";
  canvas.id = "myId";
  </code></pre>
  
  <p>Unfortunately, it didn't work. I cannot display anything with this.</p>
  
  <p>I am wondering if I miss something. Any help is appreciated.
  Thanks in advance for your help.</p>