- This topic has 2 replies, 2 voices, and was last updated 6 years, 9 months ago by .
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
These forums are now closed and remain for historical purposes.
None of the content applies to the new version 3. For support, get in touch via our contact form.
Forums › Forums › Search & Filter Pro › Getting JS to work with AJAX-loaded post results
Tagged: javascript
Hello,
We are using Search & Filter Pro with the AJAX reload functionality. For our page, the posts in the results each have a button that toggles to show more content using JS.
The problem is that when the AJAX reload happens, it creates new DOM elements so the event listener for the posts when the document first load doesn’t know about these newly created elements. Because of this, AJAX-loaded posts’ toggle buttons don’t work.
Is there a way to hook into when the AJAX finishes so our custom JS knows about these newly created DOM elements so the event listener works for them? Or is there some other solution you know about to make this functionality work?
Thank you for your help!
Nevermind. I figured it out on my own. For anyone else who might come across this problem, you can add a general event listener once the AJAX is completed using jQuery:
$( document ).ajaxComplete(function( event, xhr, settings ) {
//Code goes here
});