views:

135

answers:

2

I have the following snippet;

$("a.lightbox_image").each(function () {
        $(this).fancybox({
            'transitionIn': 'elastic',
            'transitionOut': 'elastic',
            'speedIn': 600,
            'speedOut': 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?

+1  A: 

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;
        });
    });
streetparade
The replace function works fine (have tested it), but just to double check, i tried your code above, and the result is the same as mine - it did not work i'm afraid :-(
kastru
did you also tryed with val() instead with html()
streetparade
Yeah - did not work either
kastru
+1  A: 

Problem found - turns out it is not allowed to have {} in the "this.id". After removing these from the id, it worked. Thx for the answers :)

kastru