title: jQuery Clone and add row to last row
body: <p>I want to add a row whenever the user click on the new button.I want to clone the row "tRow0" and add it to the last row of the table "tblEquipment tbody".I wrote a JavaScript function for adding the row(AddEquipment).The problem is that the row is not getting added in the last row.</p>
  
  <p>clone row : tRow0
  last row : tRow1 </p>
  
  <p>Actually the new row must added after the "tRow1" row.But the new row get added below "trActivity1_2" row.Please provide me the solution.</p>
  
  <p>my javascript function:
  function AddEquipment()
  {</p>
  
  <pre><code>var row = jQuery('#tRow0').clone(true).show().insertAfter('#tblEquipment tbody&gt;tr:last'); 
  var index = document.getElementById("hdnMaxEqpId").value; 
  
  jQuery("#tblEquipment tbody&gt;tr:last").attr("id", "tRow" + index) 
  jQuery("td:eq(0) input", row).attr("id", "chkEqp" + index);
  jQuery("td:eq(1) div:eq(0)", row).attr("id", "divEqpName" + index);
  jQuery("td:eq(1) input:eq(0)", row).attr("id", "hdnWODefEqpId" + index).attr("name", "hdnWODefEqpId" + index);
  jQuery("td:eq(1) input:eq(1)", row).attr("id", "hdnEquipmentId" + index).attr("name", "hdnEquipmentId" + index).attr("onpropertychange","");
  jQuery("td:eq(1) input:eq(2)", row).attr("id", "txtEquipment" + index).attr("name", "txtEquipment" + index);   
  jQuery("td:eq(1) img", row).attr("id", "imgshowEquipmentTree" + index).attr("onclick", "");  
  jQuery("td:eq(1) div:eq(1)", row).attr("id", "divEqpImage" + index);  
  jQuery("td:eq(2) div", row).attr("id", "divEqpHierarchy" + index);
  jQuery("td:eq(3) textarea", row).attr("id", "txtEqRemarks" + index);
  jQuery("td:eq(4) img", row).attr("id", "imgEqAttachment" + index);   
  </code></pre>
  
  <p>}</p>
  
  <p>my aspx page:</p>
  
  <pre><code>&lt;table id="tblEquipment"&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;
              &lt;/th&gt;
              &lt;th&gt;
                  Equipment&lt;/th&gt;
              &lt;th&gt;
                  Hierarchy&lt;/th&gt;
              &lt;th&gt;
                  Remarks&lt;/th&gt;
              &lt;th&gt;
                  Attachment&lt;/th&gt;
              &lt;th&gt;
                  Total Cost&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody id="tbEquipment"&gt;
          &lt;tr id="tRow0" class="trChildItem"&gt;
              &lt;td&gt;
                  &lt;input id="chkEqp0" name="chkEqp0" type="checkbox" /&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;div id="divEqpName0"&gt;
                      &lt;input id="hdnWODefEqpId0" name="hdnWODefEqpId0" type="hidden" value="0" /&gt;
                      &lt;input id="hdnEquipmentId0" name="hdnEquipmentId0" 
                          onpropertychange="AutoSaveEquipment(0);" type="hidden" value="0" /&gt;
                      &lt;input id="txtEquipment0" class="clsSpText" name="txtEquipment0" readonly /&gt;
  
                  &lt;/div&gt;
                  &lt;div id="divEqpImage0"&gt;
                  &lt;/div&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;div id="divEqpHierarchy0"&gt;
                      &amp;nbsp;&lt;/div&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;textarea id="txtEqRemarks0" class="clsSpTextArea" cols="20" 
                      name="txtEqRemarks0" rows="1"&gt;&lt;/textarea&gt;
              &lt;/td&gt;
              &lt;td&gt;
  
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr id="tActMaster0" class="trInnerChildItem"&gt;
              &lt;td&gt;
              &lt;/td&gt;
              &lt;td colspan="5"&gt;
                  &lt;div id="divActivitiesdetails0"&gt;
                  &lt;/div&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr id="tRow1" class="trChildItem"&gt;
              &lt;td&gt;
                  &lt;input id="chkEqp1" runat="server" type="checkbox" /&gt;
                  &lt;div id="divEqpEdit1"&gt;
                  &lt;/div&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;div id="divEqpName1"&gt;
                      &lt;input id="hdnWODefEqpId1" runat="server" type="hidden" value="7" /&gt;
                      &lt;input id="hdnEquipmentId1" runat="server" type="hidden" value="4" /&gt;
                      &lt;div id="divEqp1"&gt;
                          e2&lt;/div&gt;
                      &lt;div id="divEqpImage1"&gt;
                          &lt;a id="activiy1" onclick="HideActivities(1)"&gt;
  
                  &lt;/div&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;div id="divEqpHierarchy1"&gt;
                      Equipment--&amp;gt;e2&lt;/div&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;div id="divEqpRemarks1"&gt;
                      Remarks&lt;/div&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;div&gt;
                      &lt;/div&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;div&gt;
                      $0.00&lt;/div&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr id="tActMaster1" class="trInnerChildItem" jquery1275984958765="3"&gt;
              &lt;td&gt;
              &lt;/td&gt;
              &lt;td colspan="5"&gt;
                  &lt;div id="divActivitiesdetails1"&gt;
                      &lt;div id="divActivityMaster"&gt;
                          &lt;table&gt;
                              &lt;thead&gt;
                                  &lt;tr&gt;
                                      &lt;th&gt;
                                          &lt;a onclick="ActivityPopUp(0,1)"&gt;
                                          &lt;/a&gt;&lt;/th&gt;
                                      &lt;th&gt;
                                          Activity&lt;/th&gt;
                                      &lt;th&gt;
                                          Description&lt;/th&gt;
                                      &lt;th&gt;
                                          Duration&lt;/th&gt;
  
                                  &lt;/tr&gt;
                              &lt;/thead&gt;
                              &lt;tbody id="tbActivity"&gt;
                                  &lt;tr id="trActivity1_1" class="trChildItem" ondblclick="ActivityPopUp(3,1)" 
                                      onmouseleave="HideActEditDiv('1_1')" onmouseover="ShowActEditDiv('1_1',7,1)"&gt;
                                      &lt;td&gt;
                                          &lt;div id="divActEdit1_1"&gt;
                                          &lt;/div&gt;
                                      &lt;/td&gt;
                                      &lt;td&gt;
                                          &lt;input id="hdnDefActivityId1_1" runat="server" type="hidden" value="33333" /&gt;
                                          &lt;div id="divActivityName1_1"&gt;
                                              Act1&lt;/div&gt;
                                      &lt;/td&gt;
                                      &lt;td&gt;
                                          &lt;div id="divActivityDesc1_1"&gt;
                                              Ac1&lt;/div&gt;
                                      &lt;/td&gt;
                                      &lt;td&gt;
                                          &lt;div id="divActivityDuration1_1"&gt;
                                              1&amp;nbsp;Day&lt;/div&gt;
                                      &lt;/td&gt;
  
                                  &lt;/tr&gt;
                                  &lt;tr id="trActivity1_2" class="trChildItem" ondblclick="ActivityPopUp(3,1)" 
                                      onmouseleave="HideActEditDiv('1_2')" onmouseover="ShowActEditDiv('1_2',7,1)"&gt;
                                      &lt;td&gt;
                                          &lt;div id="divActEdit1_2"&gt;
                                          &lt;/div&gt;
                                      &lt;/td&gt;
                                      &lt;td&gt;
                                          &lt;input id="hdnDefActivityId1_2" runat="server" type="hidden" value="4" /&gt;
                                          &lt;div id="divActivityName1_2"&gt;
                                              Act2&lt;/div&gt;
                                      &lt;/td&gt;
                                      &lt;td&gt;
                                          &lt;div id="divActivityDesc1_2"&gt;
                                              Act2Desc&lt;/div&gt;
                                      &lt;/td&gt;
                                      &lt;td&gt;
                                          &lt;div id="divActivityDuration1_2"&gt;
                                              1&amp;nbsp;Day&lt;/div&gt;
                                      &lt;/td&gt;                                               
                                  &lt;/tr&gt;
                              &lt;/tbody&gt;
                          &lt;/table&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/td&gt;
          &lt;/tr&gt;                
  
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>