I'm trying to close a Fancybox instance from a link within the Fancybox content. I'm using parent.jQuery.fancybox.close();
as recommended in this question. It works the first time, but thereafter not. Can anyone suggest a fix?
I'm hiding my content div in the page with this:
#content {
display: none;
}
And here's the link launching the Fancybox, with that content div, which includes the link to close the Fancybox.
<a href=# id=launch>Launch</a>
<div id=content>
<p>Nunc porttitor pellentesque magna a pulvinar. Vestibulum id diam lectus. Praesent vel dictum est.</p>
<a href=# id=close>Close</a>
</div>
And this is my JS. I've tried adding the event hander to the close link on opening the Fancybox, but it didn't help.
$(document).ready(function(){
$('#launch').fancybox({
'width': 300,
'content': $('#content'),
'onClosed':function () {
$(#content).hide();
},
'onStart':function () {
$(#content).show();
$('#close').on('click', function(){
//console.log($(this).parent);
parent.jQuery.fancybox.close();
})
},
'onCleanup':function () {
$(#content).unwrap();
}
});
})
Thanks guys!