I have a filterable list that uses AJAX to update results. I am trying to add a simple JQuery function to scroll to the first item when a filter is applied. It works fine, except the scroll function runs on initial page load as well as after AJAX filtering. How can I run this only when the filters are updated?
jQuery( document ).ajaxComplete(function( event, request, settings ) {
jQuery('html, body').animate({
scrollTop: (jQuery('#td-top-of-list').offset().top - 200)
}, 500);
});
Here is the page: https://galvestondiet.com/galveston-diet-recommended-physicians/
2
Answers
Thanks for the help @benoit. The plugin author provided me with the completed AJAX event. Here is the working snippet...
This is on every ajax completed request on your page.
You need to grab the completed event from the call when you load the list.