views:

62

answers:

1

Hi guys, I have a quick question, (I hope it is quick one).

I have fancybox plugin (jquery) -- http://fancybox.net/

             $(".Sets a").fancybox({
                  'onComplete'          : function(){
                                   $('#fancybox-inner').prepend('<a href="#">'+ **clicked element rel** +'</a>')}
            });

There is a right way, to take this value, in my head now I can see , just to add a class for clicked element, at with this class can help me to detect which element was clicked.

Will be awesome to have something like

$(".Sets a").fancybox({
              'onComplete'          : function(){
                               $('#fancybox-inner').prepend('<a href="#">'+ $(this).attr("rel") +'</a>')}
        });

Thank you !!!

+2  A: 

To get the $(this) you need to add a click handler to it.

Call your fancybox this way:

$('.Sets a').click(function(){
    var _this = $(this);
    $.fancybox({
        'onComplete':function(){
            $('#fancybox-inner').prepend('<a href="#">'+ _this.attr("rel") +'</a>');
        }
    })
});
wowo_999
+1 - Don't wrap it twice though, you're cloning it :) just `_this.attr("rel")` will suffice, it's *already* a jQuery object :)
Nick Craver