Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Please don't use <code>document.write</code>. See <a href="https://stackoverflow.com/questions/802854/why-is-document-write-considered-a-bad-practice">Why is document.write discouraged</a>.</p> <p>I think your use of document.write means it overwrite's the entire page. This is working as intended if you call the function after the page has loaded. All calls to document.write after the document is loaded creates a new document. We prefer DOM manipulation since it a safe way to directly edit the DOM that doesn't involve string manipulation. </p> <p>Writing HTML as text should be left to the browser which parses a HTML file and loads it.</p> <pre><code>// feature detection for cross browser compliance. var txt = function(node, text) { if (node.innerText !== undefined) { node.innerText = text; } else if (node.textContent !== undefined) { node.textContent = text; } } function createTable(rows, columns) { var table = document.createElement("table"); table.border = '3'; var tbody = document.createElement("tbody"); var thead = document.createElement("thead"); for (var i = 0; i &lt; rows; i++) { var tr = document.createElement("tr"); for (var j = 0; j &lt; columns; j++) { var cell; if (i === 0) { cell = document.createElement("th"); if (j !== 0) { txt(cell, "x = " + j); } } else { if (j == 0) { cell = document.createElement("th"); txt(cell, "y = " + i); } else { cell = document.createElement("td"); txt(cell, operation(i, j)); } } tr.appendChild(cell); } if (i === 0) { thead.appendChild(tr); } else { tbody.appendChild(tr); } } table.appendChild(thead); table.appendChild(tbody); return table; } </code></pre> <p>Using DOM manipulation you could do it like above. There may be a few optimisations I missed. <a href="http://jsfiddle.net/FhkYT/2/" rel="nofollow noreferrer">Live example</a> (only tested chrome 10)</p> <p>At least it works as intended. </p> <p>Let me know if you want to see an implementation in say jQuery or some other DOM manipulation library. The code will be a lot nicer and more robust in terms of cross browser compliance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload