Use magnificPopup with dynamic elements
<p>I have two photos, both have the class "foto". Under each photo i added a button which allows me to delete the photo.</p>

<p>However, i can still open the photo in the galery after removing a photo from the DOM, instead of 1 of 1 photos like expected, i still have 1 of 2 at the bottom right and i can still see the deleted photo within magnificPopup's galery. Is it still in the cache?</p>

<pre><code>$(document).ready
(
    function()
    {
        $('.foto').magnificPopup
        (
            {
                type: 'image',
                closeOnContentClick: false,
                closeBtnInside: false,
                mainClass: 'mfp-with-zoom mfp-img-mobile',
                image: 
                {
                    verticalFit: true,
                    titleSrc: function(item) 
                    {
                        return item.el.attr('title') + ' &amp;middot; &lt;a class="image-source-link" href="'+item.el.attr('data-source')+'" target="_blank"&gt;image source&lt;/a&gt;';
                    }
                },
                gallery: 
                { 
                    enabled: true 
                },
                zoom: 
                {
                    enabled: true,
                    duration: 300, // don't foget to change the duration also in CSS
                    opener: function(element) 
                    {
                        return element.find('img');
                    }
                }
            }
        );
    }
);
</code></pre>

<p>Is magnificPopup not compatible with dynamic elements? Is there a way to reinitialize the function without reloading the whole page?</p>