Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

$(window).on('resize scroll', function() casing actions to get duplicated

I have used the following code

$(window).on('resize scroll', function() {
 $('.class_name').on('click', function() {
    console.log($(this).index() + " POSITION Was clicked");// I have added this to be able to track that the click event is being detected after the user scrolls past page one

});

})

on a page that has lazy loading (a page showing a list of products) so that my code would still function/work as expected with when the user scrolls down the page and newly generated contents appear on the page. But I have noticed that when I perform a click event, the action is duplicated multiple times. So from the sample code above, when I click on one of the product image the console log is posted multiple times. How do I prevent this from happening
enter image description here

Comments