title: Remove row below the row with gif image on every ajax call in c#
body: <p>Unfortunately, it added rows to the table on every ajax call:</p>
  
  <p>If I remove below code it works fine for multiple open/collapse functionality  </p>
  
  <pre><code>if ($('#tableOrderDetail_' + index + ' tr tr').length &lt;= 1)
  </code></pre>
  
  <p>Length remains 1 once ,on 2nd call the length comes greater then 1 and so it does not goes inside <strong>if condition</strong>  </p>
  
  <pre><code>&lt;tr&gt;
      &lt;td id="lding&lt;%#Container.ItemIndex + 1 %&gt;" style="display: none;"&gt;
          &lt;p&gt;Loading....&lt;/p&gt;
          &lt;img id="imgld" src="../img/loading.gif" alt="loading.." height="75px;" width="100px;" /&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>With table referred as </p>
  
  <pre><code> $('#tableOrderDetail_' + index + ' tr')
  </code></pre>
  
  <p>But with the below code ,it goes on adding the rows on every ajax call to my table name </p>
  
  <pre><code> $('#tableOrderDetail_' + index + ' tr tr')
  </code></pre>
  
  <p>Here is my Js code:</p>
  
  <pre><code> function DisplayPrdWeightGrd(index, OrderId, isAdmin) {
          $('#lding' + index).show();
          var Admin = isAdmin.toLowerCase();
          if ($('#img_' + index).attr("class") == "splashy-arrow_state_grey_expanded") {
              $('#img_' + index).attr("class", "splashy-arrow_state_grey_left");
          } else {
              $('#img_' + index).attr("class", "splashy-arrow_state_grey_expanded");
  
              var Orderid = OrderId;
  
              $.ajax({
                  type: "POST",
                  url: "../handlers/DisplayOrderDetail.ashx?OrderId=" + Orderid + "&amp;tk=" + $.now(),
                  contentType: "application/json; charset=utf-8",
                  dataType: "json",
                  success: function(data) {
  
  
                      if ($('#tableOrderDetail_' + index + ' tr tr').length &lt;= 1) {
                          $.each(data, function(i, v) {
                              setDataOnRow(index, v, i);
                          });
                      }        
                  },
                  failure: function(response) {
                      alert("fail");
                  },
                  error: function(response) {
                      alert(response);
                  }
              });
          }    
          function setDataOnRow(idx, v, i) {
              $('#tableOrderDetail_' + idx + ' tr:last').after('&lt;tr&gt;' +
                  '&lt;td width="25%" &gt;' + (i + 1) + '&lt;/td&gt;' +
                  '&lt;td width="25%" class="center"&gt;' + v.ProductName + '&lt;/td&gt;' +
                  '&lt;td width="12%" class="center"&gt;' + v.NoOfCarton + '&lt;/td&gt;' +
                  '&lt;td width="12%" class="center"&gt;' + v.ProductQuantity + '&lt;/td&gt;' +
                  '&lt;td width="12%" class="center"&gt;' + v.OriginalPrice + '&lt;/td&gt;' +
                  '&lt;td width="12%" class="center"&gt;' + v.OrderPrice + '&lt;/td&gt;' +
                  '&lt;td width="10%" class="center"&gt;' + v.Discount + '&lt;/td&gt;' +
                  '&lt;td width="12%" class="center"&gt;' + v.TotalPrice + '&lt;/td&gt;&lt;/tr&gt;');
              $('#lding' + index).hide();
          }
  
          $('#trPwd_' + index).toggle("slow");
      }
  </code></pre>
  
  <p>HTML Code:</p>
  
  <pre><code>&lt;asp:Repeater ID="rpt_us" runat="server" OnItemDataBound="rpt_us_ItemDataBound" OnItemCommand="rpt_us_ItemCommand"&gt;
      &lt;HeaderTemplate&gt;
          &lt;table class="table table-striped table-bordered dTableR"&gt;
              &lt;thead&gt;
                  &lt;tr&gt;
                      &lt;th width="7%"&gt;Detail&lt;/th&gt;
                  &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody&gt;
      &lt;/HeaderTemplate&gt;
      &lt;ItemTemplate&gt;
          &lt;tr&gt;
              &lt;td class="center" style="cursor: pointer"&gt;
                  &lt;span onclick="DisplayPrdWeightGrd('&lt;%#Container.ItemIndex + 1 %&gt;','&lt;%# Eval(" OrderId ")%&gt;','&lt;%= Convert.ToBoolean(Utility.IsAdmin()) %&gt;');"&gt;
                           &lt;img id="img_&lt;%#Container.ItemIndex + 1 %&gt;" class="splashy-arrow_state_grey_left" /&gt;
                       &lt;/span&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr style="display: none" id="trPwd_&lt;%# Convert.ToInt32(Container.ItemIndex + 1) %&gt;"&gt;
              &lt;td colspan="10" style="horizontal-align: center; padding-bottom: 15px"&gt;
                  &lt;div style="padding-left: 5px; padding-bottom: 3px"&gt; &lt;b&gt;Order Details &lt;/b&gt;&lt;/div&gt;
                  &lt;table id="tableOrderDetail_&lt;%#Container.ItemIndex + 1 %&gt;" class="table-striped table-bordered" style="align: center; width: 100%;"&gt;
                      &lt;thead&gt;
                          &lt;tr&gt;
                              &lt;th width="5%"&gt;Sr. No. &lt;/th&gt;
                              &lt;th width="35%"&gt;Product Name &lt;/th&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                              &lt;td id="lding&lt;%#Container.ItemIndex + 1 %&gt;" style="display: none;"&gt;
                                  &lt;p&gt;Loading....&lt;/p&gt;
                                  &lt;img id="imgld" src="../img/loading.gif" alt="loading.." height="75px;" width="100px;" /&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/thead&gt;
                      &lt;tbody&gt;
                      &lt;/tbody&gt;
                  &lt;/table&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/ItemTemplate&gt;
      &lt;FooterTemplate&gt;
          &lt;/tbody&gt;
          &lt;/table&gt;
      &lt;/FooterTemplate&gt;
  &lt;/asp:Repeater&gt;  
  </code></pre>
  
  <p>I tried debugger &amp; check the condition </p>
  
  <pre><code> if ($('#tableOrderDetail_' + index + ' tr tr').length &lt;= 1)
  </code></pre>
  
  <p>whose length remains 0 each time and so every time it goes inside if condition and generates the row </p>