When you call
$('.image-popup')
(with anything after the .) it will only apply to the elements that exist at that time. eg $('.image-popup').click(function() { alert("click"); }); will only put an event handler for those that exist so appending any new elements will not have that click handler (which is why we need to use event delegation for dynamically added elements).
The same applies here.
$('.image-popup').magnificPopup({
will tell magnificPopup only about the image-popups that exist at that time. When you add new ones later, it doesn't know about them.
So you need to recall your magnificPopup initialisation after you add the new elements.
Answer from freedomn-m on Stack Overflowjquery.magnific-popup not working when generated after ajax post
Using magnific popup type ajax in form Submit
Reload ajax magnific pop-up
8 - Loading an Ajax form through Ajax (Magnific Popup) - Drupal Answers
You could just display some dummy empty element (it could contain a loading icon) and load/reload content inside that element using ajax by yourself.
Not familiar with this specific plugin, but you should be able to configure the ajax portion. Try it like this:
$.magnificPopup.open({
items: {},
type: 'ajax',
ajax: {
settings: {
url: some_url,
cache:false,
dataType: 'json',
method: 'POST',
data: params
}
},
key: 'basket_popup'})
First, make sure you've included the jQuery library properly:
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
Secondly, maybe there is a conflict between jQuery with other libraries, you can try to use:
jQuery(document).ready(function ($) {
$('.image-viewer').magnificPopup({
type: 'ajax'
});
});
It sounds like you have conflict.. try adding a $ in the document.ready function
$(document).ready(function($) {
$('.image-viewer').magnificPopup({
type: 'ajax'
});
});
Or replace the $ with jQuery this
jQuery(document).ready(function(){
jQuery('.image-viewer').magnificPopup({
type: 'ajax'
});
}