Tuesday, June 4, 2024
 Popular · Latest · Hot · Upcoming
182
rated 0 times [  183] [ 1]  / answers: 1 / hits: 21098  / 11 Years ago, tue, january 7, 2014, 12:00:00

I've got this function:



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


//Fade in the Popup
$('.login_modal_message').fadeIn(500);

// Add the mask to body
$('body').append('<div class=overlay></div>');
$('.overlay').fadeIn(300);
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?


More From » jquery

 Answers
5

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


or



$(body).on( click, .post_button, .btn_favorite, function( event ) {

[#73343] Saturday, January 4, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
valentinam

Total Points: 166
Total Questions: 117
Total Answers: 81

Location: Puerto Rico
Member since Sun, Jun 27, 2021
3 Years ago
;