title: Object JavaScript, cannot read property of undefined... That was read just before
body: <p>I try to make an object that move, resize and change the color of a div randomly every second.</p>
  
  <p>In my classical HTML page there is </p>
  
  <pre><code>&lt;div id="Rectangle1"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>Here is my code </p>
  
  <pre><code>var colors = ["red","yellow","blue","dark","green","pink","purple"];
  
  function Rectangle(tag){
  
      this.moveNShape = function() {
          //Defining new values
          this.width = Math.floor(Math.random()*250)+50; 
          this.height = Math.floor(Math.random()*250)+50; 
          this.x = Math.floor(Math.random()*400)+100; 
          this.y = Math.floor(Math.random()*400)+100; 
          this.color = colors[Math.floor(Math.random()*7)];
          //Update the view
          this.tag.css("position","absolute").css("height",this.height).css("width",this.width).css("left",this.x).css("top",this.y);
          this.tag.css("backgroundColor",this.color);
          //Launch again
          setTimeout(this.moveNShape,1000);
  
      }
  
      this.tag = $('#'+tag);
      this.moveNShape();
  
  }
  
  var rect1 = new Rectangle("Rectangle1");
  </code></pre>
  
  <p>It works one time and after I get the error "Cannot read property 'css' of undefined". I tried to rewrite it in many ways but I can't find a solution.</p>
  
  <p>Can you explain my mistake ?</p>
  
  <p>Thank you =)</p>