I've been referencing this post regarding Bootstrap's scrollspy component. In my code, I instantiate a new scrollspy to spy on the body
element using:
$("body").scrollspy({ offset: 25 });
Later on in my code, I make an AJAX call and add/remove elements from the page. This causes the scrollspy to be misaligned, so I need to refresh the scrollspy. I have tried performing this refresh operation many ways, such as:
$("body").scrollspy("refresh");
and
$('[data-spy="scroll"]').each(function () {
$(this).scrollspy('refresh');
});
However, neither of these code snippets bring about any change in the behavior of the scrollspy. I believe this is because the scrollspy is spying directly on the body
element, but I am unsure of how to have the scrollspy refresh following my AJAX calls. Does anyone know how I might refresh my scrollspy?