Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Use <code>insertBefore()</code>:</p> <pre><code>$('#add').click(function(){ $('&lt;tr&gt;&lt;td&gt;one&lt;/td&gt;&lt;td&gt;two&lt;/td&gt;&lt;/tr&gt;').insertBefore('#sum'); })​ </code></pre> <p><a href="http://jsfiddle.net/davidThomas/6Zrhs/" rel="nofollow">JS Fiddle demo</a>.</p> <p>You could also simply use multiple <code>tbody</code> elements, one to contain the <code>#sum</code> row, and the others for the, in this example, <code>#content</code>:</p> <pre><code>&lt;table id="table"&gt; &lt;tbody id="content"&gt; &lt;tr&gt;&lt;td&gt;one&lt;/td&gt;&lt;td&gt;two&lt;/td&gt;&lt;/tr&gt; &lt;/tbody&gt; &lt;tbody&gt; &lt;tr id="sum"&gt;&lt;td&gt;sum&lt;/td&gt;&lt;td&gt;sum2&lt;/td&gt;&lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p>With the jQuery:</p> <pre><code>$('#add').click(function(){ $('#content').append('&lt;tr&gt;&lt;td&gt;one&lt;/td&gt;&lt;td&gt;two&lt;/td&gt;&lt;/tr&gt;'); })​ </code></pre> <p><a href="http://jsfiddle.net/davidThomas/6Zrhs/1/" rel="nofollow">JS Fiddle demo</a>.</p> <p>Or, possibly, using a <code>tfoot</code> (though I'm not sure that this a proper use-case for a <code>tfoot</code> element:</p> <pre><code>&lt;table id="table"&gt; &lt;tfoot&gt; &lt;tr id="sum"&gt;&lt;td&gt;sum&lt;/td&gt;&lt;td&gt;sum2&lt;/td&gt;&lt;/tr&gt; &lt;/tfoot&gt; &lt;tbody id="content"&gt; &lt;tr&gt;&lt;td&gt;one&lt;/td&gt;&lt;td&gt;two&lt;/td&gt;&lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p>And jQuery:</p> <pre><code>$('#add').click(function(){ $('table tbody').append('&lt;tr&gt;&lt;td&gt;one&lt;/td&gt;&lt;td&gt;two&lt;/td&gt;&lt;/tr&gt;'); })​ </code></pre> <p><a href="http://jsfiddle.net/davidThomas/6Zrhs/2/" rel="nofollow">JS Fiddle demo</a>.</p> <p>References:</p> <ul> <li><a href="http://api.jquery.com/insertBefore/" rel="nofollow"><code>insertBefore()</code></a>.</li> <li><a href="http://www.w3.org/TR/html4/struct/tables.html#h-11.2.3" rel="nofollow">Tables in HTML documents: Row groups: the <code>THEAD</code>, <code>TFOOT</code>, and <code>TBODY</code> elements</a>.</li> </ul>
 

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