Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you don't wish to use jQuery, there are a couple of simple functions you could use, like <code>cloneNode()</code>, <code>createElement()</code> and <code>appendChild()</code>. Here is a simple demonstration that appends a row to the end of the table using either the clone or create method. Tested in IE8 and FF3.5.</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; function cloneRow() { var row = document.getElementById("rowToClone"); // find row to copy var table = document.getElementById("tableToModify"); // find table to append to var clone = row.cloneNode(true); // copy children too clone.id = "newID"; // change id or other attributes/contents table.appendChild(clone); // add new row to end of table } function createRow() { var row = document.createElement('tr'); // create row node var col = document.createElement('td'); // create column node var col2 = document.createElement('td'); // create second column node row.appendChild(col); // append first column to row row.appendChild(col2); // append second column to row col.innerHTML = "qwe"; // put data in first column col2.innerHTML = "rty"; // put data in second column var table = document.getElementById("tableToModify"); // find table to append to table.appendChild(row); // append row to table } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;input type="button" onclick="cloneRow()" value="Clone Row" /&gt; &lt;input type="button" onclick="createRow()" value="Create Row" /&gt; &lt;table&gt; &lt;tbody id="tableToModify"&gt; &lt;tr id="rowToClone"&gt; &lt;td&gt;foo&lt;/td&gt; &lt;td&gt;bar&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt;</code></pre> </div> </div> </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.
    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