0

I am having a real simple/stupid problem and my lack of jQuery knowledge isn't helping.

In principle I have a galley with multiple pictures and want to use a sibling-<div>-block with some HTML markup as title with FancyBox. Here's a bare-bones fiddle of my problem:

HTML:

<div class="someClass">
  <a title="some title"
     class="fancybox"
     href="http://fancyapps.com/fancybox/demo/1_b.jpg">
    <img src="http://fancyapps.com/fancybox/demo/1_s.jpg"
         alt=""/>
  </a>
</div>

<div class="captionClass">
     this should be <br /> the <b>caption</b>
</div>

JavaScript:

$(".fancybox").fancybox({

  'beforeLoad' : function() {
     this.title = $(this).siblings('.captionClass').html();
  }

 });

Any help would be much appreciated :)

Phil Strahl
  • 165
  • 1
  • 1
  • 8

1 Answers1

1

You should change the function to afterLoad

$(".fancybox").fancybox({
    afterLoad: function () {
        this.title = $(this.element).parent().siblings('.captionClass').html()
    },
    helpers: {
        overlay: {
            css: {
                'background': 'rgba(58, 42, 45, 0.95)'
            }
        }
    }
});

DEMO: http://jsfiddle.net/6gvjsd9u/

Sam Battat
  • 5,725
  • 1
  • 20
  • 29