Skip to content
Advertisement

javascript is unable to working on infinite scroll

I have a website which have multiple posts and each post have a like button with auto timeout modal popup. When scrolling down, more posts loaded with infinite.js. Which load the posts. The problem : In the first page the like button with timeout modal popup does work. But when the posts load in infinitely the modal popup is not working anymore.

JavaScript
JavaScript

first it loads 10 posts after scrolling bottom down 10 posts loads again which is done by infinite.js I want to add the same modal popup function to every infinite container. But somehow its not working in the infinite container instead of the first page which is already loaded.

Advertisement

Answer

Have a look into event delegation. Basically, you won’t attach the listener to elements, but rather to the page and make your handler dependent on the event details.

So (in vanilla) it would be something like this:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement