开发者

Fancybox - getting html from element based on id?

I have the following snippet;

$("a.lightbox_image").each(function () {
        $(this).fancybox({
            'transitionIn': 'elastic',
            'transitionOut': 'elastic',
            'speedIn': 600,
            'sp开发者_StackOverfloweedOut': 200,
            'content': $('#lightbox_image_content_'+this.id.replace('lightbox_image_','')).html()
        });
    });

But the above does not get the content from the element referenced to in the content property - what am i doing wrong?


the replace function needs a regular expression so try replace(/lightbox_image_/, '') and try to get the val() in stead the html()

$("a.lightbox_image").each(function () {
  var id = "lightbox_image_content_"+this.id.replace(/lightbox_image_/,'');
  var content = $("#"+id).html();
        $(this).fancybox({
            'transitionIn': 'elastic',
            'transitionOut': 'elastic',
            'speedIn': 600,
            'speedOut': 200,
            'content': content;
        });
    });


Problem resolved. It turns out it is not allowed to have {} in the this.id. After removing these from the id, it worked.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜