Sanjay
Sanjay

Reputation: 231

How to close magnific popup by jquery

I m using a magnific popup in my project. To close this popup by jQuery I am using $('.mfp-close').click(); and it's working but I have need to close by another way.

Please help me if any other way. Thanks in advance.

Upvotes: 22

Views: 59608

Answers (7)

NJENGAH
NJENGAH

Reputation: 1277

This is the only way I could make the popup close:

$('body').on('click', '#some-div', function(e) {
    e.preventDefault();
    $.magnificPopup.close();
});
 

Upvotes: 0

Urmas Tassenberg
Urmas Tassenberg

Reputation: 1

magnificPopup iframe:

window.parent.$.magnificPopup.close();

Upvotes: 0

ClaudioC
ClaudioC

Reputation: 1545

The only one that works for me is :

$jQ('#close_popup').on('click',function(){                                                      
    $jQ.magnificPopup.proto.close.call(this);
}); 

Upvotes: 5

Lem
Lem

Reputation: 419

Take a look here http://dimsemenov.com/plugins/magnific-popup/documentation.html#api

These are some ways you can close this pop up:

var magnificPopup = $.magnificPopup.instance; // save instance in magnificPopup variable
magnificPopup.close(); // Close popup that is currently opened

or

$.magnificPopup.close();

or

$('your-selector').magnificPopup('close');

For me, only the third one worked efficiently.

Upvotes: 16

Konstantine Kalbazov
Konstantine Kalbazov

Reputation: 2673

Just use $.magnificPopup.close()

Upvotes: 50

Bobby5193
Bobby5193

Reputation: 1625

try this:

var magnificPopup = $.magnificPopup.instance; 
// save instance in magnificPopup variable
magnificPopup.close(); 
// Close popup that is currently opened

Upvotes: 41

Rohan Kumar
Rohan Kumar

Reputation: 40639

If you have open the pop up then it will return an magnific object, Using that object you can call close method.

Try it like,

var mgObj=$('your-selecter').magnificPopup({
   // you options
});

// code to close pop up on clicking a button
$(document).on('click','button',function(){
    if(mgObj)
    {
        mgObj.close();
    }
});

Upvotes: 0

Related Questions