Use Magnific Popup with AJAX-loaded content
See original GitHub issueHi,
I have some content that is loaded through AJAX. Magnific doesn’t work with that content because the event listeners fire on page load, but the the AJAX-loaded content is not yet inserted in the page at that point.
The only workaround for this that I know of is to use inline javascript on the AJAX-loaded content. I tried to do something like:
<a class="test-popup-link" href="path-to-image.jpg" onclick="magnificPopup({type: 'image'}).magnificPopup('open');">Open popup</a>
But unfortunately it doesn’t seem to work. I get ReferenceError: magnificPopup is not defined
, even though the magnific-popup.js file is included in the page.
Any help on how to get this to work would be appreciated. Thanks!
Issue Analytics
- State:
- Created 6 years ago
- Comments:5
Top Results From Across the Web
Is it possible to pass data via the post method to magnific ...
I'm using magnific popup and ajax loading content into it and passing values to the ajax content by appending a query string to...
Read more >Display Magnific Popup using AJAX on Page Load
Dear Sir/Madam I found a solution to display an Image on pageload ...
Read more >Magnific Popup Documentation - Dmitry Semenov
The complete guide on how to use Magnific Popup - the open source responsive ... Popup has four types of content: image ,...
Read more >Magnific Popup - loading content from external page via ajax ...
data = jQuery(mfpResponse.data).find('#gallery'); console.log('Ajax content loaded:', mfpResponse); }, ajaxContentAdded: function() { $('# ...
Read more >Réinitialise magnific popup after a filtering operation - Toolset
Solution: The user has activated AJAX on the view, after the first-page load, any further AJAX calls will not rebuild the lightbox. The...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
use
document
as main selector, but if you think it’s too general, you can change it to any selector as long as it’s not included inside AJAX dom element,and then put your own selector (selector inside AJAX dom element) to
delegate
optionsIt works for me, no need to re initialize
On document load initialize mp as normal:
In your ajax call, trigger the binding of magnific popup after the ajax content is loaded:
In your magnificPopup jQuery function: