javascriptjqueryjquery-eventsfancybox-2

Is fancybox self binding?


I have written a gallery plugin which uses fancybox for the popup. This all works but I have an issue where I do an ajax call and replace all the images depending on some filters.

$.ajax({
    url: this.action,
    type: this.method,
    data: $(this).serialize() + '&filter=submit&isAjax=true',
    success: function (result) {
        photoHolder.html(result);
    }
});

Now I would expect that I should have to rebind the fancybox to the new content so in my success I thought I would have had to do something like:

photoHolder.html(result);
photoHolder.find('.fancybox').fancybox();

However I have not, but the fancybox is working on the new content. Does anyone know why this is?


Solution

  • Yes, it does work for run-time added elements.

    See the "live" parameter in the docs. true is the default.