Using JQuery, I am loading a div from an external HTML page into fancybox and am building the link using variables. It is taking two clicks to open it. The first, I believe, is only initiating it. But I don’t know how to fix it. Is there a better way to be doing this?
The HTML is here:
<a class="BannerVideoAwesome fancybox" id="series900" border="0" href="/mkting/Videos/Speakers.html"><img src="/images/titles/CM/series-speakers-video.jpg" border="0" align="left" /></a>
The jQuery is here:
$('a.BannerVideoAwesome').live('click', function(e){
e.preventDefault();
var url = $(this).attr('href');
var grabVid = '#' + $(this).attr('id');
vidObject = url + grabVid;
var vidContents = vidObject.html();
alert(vidContents);
$.fancybox({
//'href': url,
'content':'vidContents'
});
Thank you so much in advance for any help someone can give me. I have been struggling with this for days.
I think the title of your post is a little bit misleading. Anyway, if I understood right, you just want to load a partial content (DIV) from an external html file into fancybox.
In your example, the file episodeSpeakers.html contains a DIV with ID=’series900′
If the above is correct, then you don’t need to use jQuery live(), but binding fancybox to a click() and use ajax and dataFilter to select the content.
With the same html, this script should do the trick:
or you may use
instead of
IMPORTANT : Due to some cross-browser issues, don’t use the dataFilter solution above.
It would be better to use the fancybox’s inline method, adding the partial content (from the external html file) into a hidden DIV within your calling html document and then move it from there into fancybox. It requires (of course) to add such DIV. e.g.:
Then use this script:
that works on most browsers.
BTW, the onCleanup option fixes this bug