JavaScript Creating a Table dynamically : <p>I am trying to create a table using JS with random number of rows. The table does create, rows are being inserted outside of the 'for' loop, but when I place rows creation inside the loop, it doesn't create them:</p>

<pre><code>function createTable (rn){
   var table.document.createElement("table");
   document.getElementById("anchor").appendChild(table);
   for(var r=0;r&lt;rn;r++){
      var tr=table.insertRow(r); 
      var td1=tr.insertCell(0), td2=tr.insertCell(1);
      td1.innerHTML = "td1";
      td2.innerHTML = "td2";      
   }
}
</code></pre>
