inserting a row on click jquery
<p>I am struggling to figure out why my code is not working. I have a table with a text field, 2 checkboxes and an add button in a row. I have 4 rows on load, I have a hyperlink when clicked should add a new row at the end of the table. My code is adding the row alternatively starting from the first row. My last row is 4 which I am cloning. The sequence I am getting when click on the link
1,4,2,4,3,4,4,4</p>

<p>I don't understand where I am making a mistake, I have been banging my head for this for last 4-5 hours</p>

<pre><code>&lt;table id="setting"&gt;
&lt;tr&gt;&lt;td&gt;&lt;input name="name_1" type="text" /&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type="checkbox" /&gt; &lt;/td&gt;
&lt;td&gt;&lt;input type="checkbox" /&gt; &lt;/td&gt;
&lt;td&gt;&lt;input type="button" /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;input name="name_2" type="text" /&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type="checkbox" /&gt; &lt;/td&gt;
&lt;td&gt;&lt;input type="checkbox" /&gt; &lt;/td&gt;
&lt;td&gt;&lt;input type="button" /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;input name="name_3" type="text" /&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type="checkbox" /&gt; &lt;/td&gt;
&lt;td&gt;&lt;input type="checkbox" /&gt; &lt;/td&gt;
&lt;td&gt;&lt;input type="button" /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;input name="name_4" type="text" /&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type="checkbox" /&gt; &lt;/td&gt;
&lt;td&gt;&lt;input type="checkbox" /&gt; &lt;/td&gt;
&lt;td&gt;&lt;input type="button" /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;

$('#add').on("click", function(e) {
     e.preventDefault();
     e.stopPropagation();
     $clone = $('#settings tbody tr').filter(":last").clone(true).insertAfter('#settings tbody tr').filter(":last").val('');
</code></pre>

<p>I tried this code below from one of the questions in stackoverflow. This one didn't work for me, i don't know why</p>

<pre><code>$('#settings tbody tr:last').clone(true).insertAfter('#settings tbody&gt;tr:last');
$('#settings tbody tr:last').val('');
</code></pre>
