Q:

Fancybox on click with element binding in Yii CGridView with ajax Pagination

I am using Yii CGridView with ajax Pagination and one of the column is Link for image or inline ajax content and i want to use FancyBox to the column.
When i use pagination i lose the binding on the new element.
if i try to make it on element click i always get error if the element has fancy-box already like below 
$('a.fancy-img').live('click', function () {
     $(this).fancybox({});
      return false;
});

But I always get javascript error if i click twice on the same link.

A:

The problem you are trying to initialize fancybox for the element twice so your javascript breaks and doesn't work.
You can add class or some attribute to the element that has already has Fancybox init so you don't initialized it again for the same element and your javascript beaks as below :
$('a.fancy-img').live('click', function () {
            var El = $(this);
            $(this).fancybox({});
            if (!El.hasClass('fancy-box-init')) {
                El.addClass('fancy-box-init');
                El.trigger('click');
            }
            return false;
 });

