javascript - Unable to remove table rows to replace with new one -


i using bootstrap in 1 of java project based on play framework. on 1 of clicks populating data in table fetching div each row of table (based on how many row's data send server). fetching whole div html $.get() , using .last() method populating data in various columns of fetched table. makes table runtime-loaded-element rather static element.

while clicking button first time, fine. failing remove existing rows , replace them new rows on subsquent clicks, instead new data binded below existing data.

i have tried remove existing rows before fetching new rows using .remove(), .empty(), .removedata() on divs fetched previously. tried use .each() on existing divs remove them somehow nothing of works me.

what have concluded either of below:

  1. the removal methods working both on old , newly fetched divs (as both have common class).

  2. these removal methods not work on runtime-loaded-elements (delegate say).

it has been while fiddling issue , getting nowhere. can point me better direction of achieving same.

my basic jquery function used above follows. have tried using various methods on same, shows latest method had used:

$(document).ready(function(){     $('#searchbutton').click(function(){         $('body').find('.jresultlist').empty();         $("#jerrdisplayy").css("display","none");         var input,div,range;         input= $("#inputfield").val();         $.ajax({                 url: "/fetchptidatas",                 data: {num:$('#inputfield').val()}, //{id:$('#conbid').val()},                 timeout: 10000,                 type: "post",                 cache: false,                 contenttype: "application/x-www-form-urlencoded",                 datatype: "json",                 beforesend:function(jqxhr, options) {                     if(input.length<7||input.length>11){                         alert("please enter valid input");                             jqxhr.abort();                     }                   }             }).fail(function(jqxhr, textstatus, errorthrown){                 alert("ajax call failed");             }).done(function(resp, textstatus, jqxhr){                 if(resp.errorcode){                     $("#jerrdisplayy").css("display", "block");                     $('.jerrorr').html("we couldn't not entered code. please enter valid code");                 }else{                     range= resp.pagecontainerlist.length;                     alert(range);                     $.get("/fetchresultlist", function(data){                         $('body').find('.tableheader').css('display', 'block');                         $('jresultlist').each(function(){                             $('jresultlist').remove();                         });                         (var i=0; <=range; i++) {                             $('body').find('.jcontrlist').append(data);                             div = $('body').find('.jcontrlist .jresultslist').last();                             div.find('.accordion-body').attr('id', "collapse" + i);                             div.find('.accordion-toggle').attr('href', "#collapse" + i);                             div.find('.jcontno').html(resp.pagecontainerlist[i].container);                              }                      });                                         }                         });     }); }); 

thanks in advance!!!


Comments