Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>With identifier (HTML structure can be changed)</strong></p> <p>You have to 'attach' the link to the table. You can use the data-... attribute for example, but an id is also ok. NB: You cannot put an anchor directly in a <code>table</code>, so Vadym Petrychenko's solution is still invalid HTML.</p> <pre><code>&lt;a href="#" class="showrows" data-table="table1"&gt;Add row to table 1&lt;/a&gt; &lt;table id="table1"&gt; &lt;tr class="cache"&gt; &lt;td&gt;&lt;input type="text" size="15"&gt;Table 1 cell 1&lt;/td&gt; &lt;td&gt;&lt;input type="text" size="15"&gt;Table 1 cell 2&lt;/td&gt; &lt;/tr&gt; &lt;tr class="cache"&gt; &lt;td&gt;&lt;input type="text" size="15"&gt;Table 1 cell 3&lt;/td&gt; &lt;td&gt;&lt;input type="text" size="15"&gt;Table 1 cell 4&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;a href="#" class="showrows" data-table="table2"&gt;Add row to table 2&lt;/a&gt; &lt;table id="table2"&gt; &lt;tr class="cache"&gt; &lt;td&gt;&lt;input type="text" size="15"&gt;Table 2 cell 1&lt;/td&gt; &lt;td&gt;&lt;input type="text" size="15"&gt;Table 2 cell 2&lt;/td&gt; &lt;/tr&gt; &lt;tr class="cache"&gt; &lt;td&gt;&lt;input type="text" size="15"&gt;Table 2cell 3&lt;/td&gt; &lt;td&gt;&lt;input type="text" size="15"&gt;Table 2 cell 4&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>JQuery code:</p> <pre><code>$(document).ready(function() { $('tr.cache').css("display","none"); $('.showrows').live('click',function(e) { e.preventDefault(); $('table#' + $(this).attr('data-table') + ' tr:hidden:first').show("fast"); }); }); </code></pre> <p>See <a href="http://jsfiddle.net/Mikey/KnRFf/" rel="nofollow">http://jsfiddle.net/Mikey/KnRFf/</a></p> <p><strong>Without identifier</strong></p> <p>I you are really using this HTML structure, it is also possible to link to the table after the anchor with <code>$(this).next('table').find('tr:hidden:first').show("fast");</code></p>
 

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