dimsemenov / Magnific-Popup

Light and responsive lightbox script with focus on performance.
http://dimsemenov.com/plugins/magnific-popup/
MIT License
11.39k stars 3.48k forks source link

Closing Magnific-Popup ajax page through button #1055

Open Tanel-F opened 6 years ago

Tanel-F commented 6 years ago

I'm trying to close the Magnific-Popup page by clicking a button with the following code (unfortunately nothing happens):

<button class="bigRed" onclick="$.magnificPopup.close();">Go back</button>

According to dimsemenov.com/plugins/magnific-popup/documentation.html

$.magnificPopup.close(); // Close popup that is currently opened (shorthand)

I am using the Magnific-Popup code as part of a WordPress portfolio Ajax page, the theme I am using is H-Code by Themezaa. Any feedback is greatly appreciated.

dariodev commented 6 years ago

<button class="bigRed">Go back</button>

$('.bigRed').click(function() {
    e.preventDefault();
    $.magnificPopup.close();
});
Tanel-F commented 6 years ago

Thank you for the reply. Could you please explain what is the purpose of: e.preventDefault();

Grexery commented 6 years ago

It tells a browser to ignore the event and do not invoke a default handler(s) for it. For instance, in case of clicking on a submit button browser doesn't submit a form.