Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call fancybox with jquery element

I know there is a way to call fancybox manually with a string of html like so:

$.fancybox("<div>foo</div>")

However, i want to instead pass a jQuery object to the fancybox so i can retain things like .data() and click() events i have already added:

var $fooObj = $("div.foo").data("foo","bar");
$.fancybox($fooObj);

Is this possible somehow?

like image 920
Abadaba Avatar asked Dec 22 '22 21:12

Abadaba


2 Answers

You just need to set it as the content property in the options you pass into $.fancybox(), like this:

$.fancybox({
    content: $fooObj 
});

You can test it out here.

like image 66
Nick Craver Avatar answered Dec 24 '22 09:12

Nick Craver


function LaunchFancyBox(code)
{
    jQuery.fancybox({
        content: code 
    });     
}

And in the onclick/click:

<a href="#" onclick="LaunchFancyBox('<div>test</div>'); return false;">Launch it baby</a>!
like image 31
Simon Avatar answered Dec 24 '22 10:12

Simon