13

I'm trying to destroy Fancybox. I haven't found any method to do it in documentation. How to destroy it after it was initialized?

This doesn't work:

$("a").unbind('fancybox').unbind('click');

Testing code: http://jsfiddle.net/martinba/yy3cw/2/

I use current version 2.1.4.

Martin Ille
  • 6,747
  • 9
  • 44
  • 63

4 Answers4

15

In order to unbind fancybox you have to unbind events under fb-start namespace from document:

$(document).unbind('click.fb-start');

Though, I don't know why developer made it so unobvious.

http://jsfiddle.net/dfsq/yy3cw/16/

dfsq
  • 191,768
  • 25
  • 236
  • 258
  • If I have multiple fancybox instances on my page, like image gallery - is there any way to unbind only specific images but not the whole thing? – webdevbyjoss Dec 06 '13 at 10:50
  • @Passer by I suggest that you post a new answer with your code. – dfsq Nov 07 '16 at 11:07
2

Try to call:

.unbind('click.fb') to unbind fancybox.

like:

$('.group').unbind('click.fb')
CloudyMarble
  • 36,908
  • 70
  • 97
  • 130
  • Unfortunatelly, it doesn't work. Here it is: http://jsfiddle.net/martinba/yy3cw/11/ Click on init button and then destroy. "FancyDevil" is still there. – Martin Ille Mar 01 '13 at 09:48
  • This worked for me. The 'click.fb-start' didn't. I guess it depends on the FB version. – igasparetto May 13 '14 at 09:36
1

You can unbind every fancy box by running:

$(document).unbind('click.fb-start');

Or if you need to unbind a specific selector, you can undelegate it:

var selector = 'a.my-fancy-box';
selector = selector + ":not('.fancybox-item, .fancybox-nav')";
$(document).undelegate(selector, 'click.fb-start');

Or alternatively:

// Bind
$('a.my-fancy-box').fancybox({live: false});

// Unbind
$('a.my-fancy-box').unbind('click.fb');
Passer by
  • 562
  • 9
  • 14
0

As it was mentioned here earlier: $(document).unbind('click.fb-start'); But you also might want to add this option to the fancybox init call: live:false

Pinny
  • 206
  • 2
  • 10