Saulius Slavinskas Saulius Slavinskas - 5 months ago 37
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?


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 ) {