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();
}
2

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

7 Comments

click() is certainly not deprecated
.click() is not deprecated. However, .live() is.
From what I remember, it was suggested to avoid it. In newer versions, it is now aliased to .on() since people kept on using it. Amended answer with your feedback.
Eli Sand wrote up a good summary of on() vs click() vs. live() here: stackoverflow.com/a/10082242/605643
so if I were to change to use on, would I still need to remove the script or could I just call the function again?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.