Saulius Slavinskas Saulius Slavinskas - 1 year ago 118
Ajax Question

Jquery function doesn't work after Ajax call

I've got this function:

$(document).ready(function() {
$('.post_button, .btn_favorite').click(function() {

//Fade in the Popup

// Add the mask to body
$('body').append('<div class="overlay"></div>');
return false;

My page loads content with favourite buttons, but after Ajax call and generated additional new content the function doesn't work when you click new content's buttons. What could be not right?

Answer Source

That is because you are using dynamic content.

You need to change your click call to a delegated method like on

$('.post_button, .btn_favorite').on('click', function() {


$("body").on( "click", ".post_button, .btn_favorite", function( event ) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download