0

I have a script that makes a table responsive (footable). This works great for my needs but I use some ajax to bring in some more table rows, but the script doesn't affect these new rows.

I have tried to reinitiate the script after my ajax has completed but it doesn't work.

My question is, can I remove the affecting jquery so that I can reapply it after the data has been loaded?

My jQuery:

jQuery(document).ready(function ($) {
table();

$('#moreevent').click(function(){
var last = $('#the-event tr').length;
$.ajax({
    type: "POST",
    url: "ajax.php",
    data: { levent: last }
}).done(function( data ) {
    $('#the-event').append(data);
    cardbox();
    table();
});

return false;
});

});

function cardbox(){
jQuery('.e-info-more-cont').hide();
jQuery('.e-info-more').mouseover(function(){
    jQuery(this).css({"z-index":"1001"});
    jQuery(this).nextAll(".e-info-more-cont").show();
}).mouseout(function(){
    jQuery(this).nextAll(".e-info-more-cont").hide();
    jQuery(this).css({"z-index":""});
});
}

function table(){

jQuery('.footable').footable();
}
jhodgson4
  • 1,566
  • 3
  • 20
  • 35

1 Answers1

1

You are using .click() which is deprecated and does not handle dynamically added items. Depending on your jQuery version, either use .on() (recommended), or .live()

Edit: As suggested, .click() is not deprecated, however it is still suggested to use .on() wherever possible.

Nick Andriopoulos
  • 10,313
  • 6
  • 32
  • 56