title: HTML5, JavaScript and drawing multiple rectangles in a canvas
body: <p>Why won't my multiple rectangles draw in the canvas?</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
    &lt;head&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;script src="Scripts/jquery-1.9.1.min.js"&gt;&lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;canvas id="myCanvas" width="500" height="500" style="border:1px solid red"&gt;
        &lt;p&gt;Your browser doesn't support canvas.&lt;/p&gt;
      &lt;/canvas&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  
  &lt;script type ="text/javascript"&gt;  
    function Shape(x, y, w, h, fill) {
      this.x = x;
      this.y = y;
      this.w = w;
      this.h = h;
      this.fill = fill;
    }
  
    // get canvas element.
    var elem = document.getElementById('myCanvas');
  
    // check if context exist
    if (elem.getContext) {
  
      var myRect = [];
  
      myRect.push(new Shape(10, 0, 25, 25, "#333"))
      myRect.push(new Shape(0, 40, 39, 25, "#333"))
      myRect.push(new Shape(0, 80, 100, 25, "#333"))
  
      context = elem.getContext('2d');
      for (i in myRect) {
  
        //console.log(x);
  
        context.fillRect(i.x, i.y, i.w, i.h)
      }
      //// x, y, width, height
      //context.fillRect(0, 0, 50, 50);
  
      //// x, y, width, height      
      //context.fillRect(75, 0, 50, 50);
    }
  &lt;/script&gt;  
  </code></pre>
  
  <p>Thanks for help.</p>