Tonight I had to figure out a way to have a secondary close button for the Fancybox modal window I’ve been working on for a client. I hadn’t come across this before but know how magically neat jQuery is, I knew there had to be a way.
Turns out it’s actually quite simple. Basically all I had to do was add an class (or id) to the object that I want to trigger the close and call the function using jQuery.
Here’s the code that worked for my instance. I had an image that I wanted to trigger the close event on click.
<script type=”text/javascript”>
$(function() {
$(‘img.close-popup’).click(function(event) {
$.fancybox.close(true);
});
});
</script>
Easy enough!