In my fancybox, I’m trying to set the ‘title’ attribute to the alt value of an img wrapped by the fancybox link. In other words,
$("a.fancypic").fancybox({
'titlePosition' : 'inside',
'padding' : 0,
'autoScale' : true,
'transitionIn' : 'none',
'transitionOut' : 'none',
'href' : this.href,
'type' : 'image',
'title' : this.find('img').attr( 'alt' )
});
When I remove the ‘title’ attribute, the fancybox works fine. However, with the ‘title’ attribute, the fancybox fails to show, and no error is shown in firebug. Any ideas on what’s wrong here?
Given that you’re using
this.href, I’m going to guess thatthisis a DOM element, not a jQuery selection. jQuery methods likefindonly work on jQuery selections.So do this: