Archived topic
jquery event on load more posts in infinite scroll
5 replies · Started by Joshua Vandercar on August 9, 2018
I'd like to run a jquery function when more posts are loaded via infinite scroll. Is there an event to which I can bind? Thanks!
Hi there,
Infinite Scroll for posts is a built in feature:
https://docs.generatepress.com/article/blog-content-layout/#archives
Let me know if this helps :)
Yes, I have that enabled. Is there a specific javascript event that is triggered after the additional posts are loaded? I have a function that needs to target and modify those elements that are being added to the DOM.
Give this a shot:
jQuery( document ).ready( function($) {
var $container = $( '#main article' ).first().parent();
$container.on( 'append.infiniteScroll', function( event, response, path, items ) {
// Do stuff
} );
} );
Make sure to load this JS only on pages that have infinite scroll initiated.
Let me know :)
Yes! Thank you, Tom! That got the job the done.
Awesome! You're welcome :)