Magnific-popup: How to destroy

Created on 20 Mar 2015  路  4Comments  路  Source: dimsemenov/Magnific-Popup

I'm looking to destroy the magnificPopup handlers on my anchor tags as I have a filter that hides some and I'd like to re-add the handlers to just the ones that are visible, but in order to do that I need to remove it from the hidden ones.

Most helpful comment

A refresh function on a container would be helpful:)

I could make the refresh (destroy and recreate) work only with setTimeout delay.

setTimeout(function() {
        // Remove event and data (not sure about data)
    $('a', $galleryContainer).off('click')
    $('a', $galleryContainer).removeData('magnificPopup')

        // Custom function to initiate MagnificPopup
    initMagnificPopup($('.filtered a', $galleryContainer))
}, 500)

All 4 comments

  • If you opened popup directly: its instance is destroyed when you call the close() method.
  • If you initialize popup so it's bound to the DOM element (via $.fn.magnificPopup): to detach it all you need is to remove() the element, or unbind click event ($.fn.off('click.magnificpopup')) and optionally remove the stored options $.fn.removeData('magnificPopup').

A refresh function on a container would be helpful:)

I could make the refresh (destroy and recreate) work only with setTimeout delay.

setTimeout(function() {
        // Remove event and data (not sure about data)
    $('a', $galleryContainer).off('click')
    $('a', $galleryContainer).removeData('magnificPopup')

        // Custom function to initiate MagnificPopup
    initMagnificPopup($('.filtered a', $galleryContainer))
}, 500)

YO BRO!

Thanks @klihelp
very helpful

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jglesner picture jglesner  路  3Comments

klihelp picture klihelp  路  4Comments

ghost picture ghost  路  5Comments

samholmes picture samholmes  路  5Comments

amir-rahnama picture amir-rahnama  路  4Comments