I have the following fancybox code:
$('.fancybox').fancybox({
'autoScale' : false,
'href' : $('.fancybox').attr('id'),
'type':'iframe',
'padding' : 0,
'closeClick' : false,
//some other callbacks etc
the problem is I have twenty different A tag id’s on the page and I want the fancybox href attribute to take the id of the clicked element, ie the one that triggered the event.
I have tried several things, none of them have worked!
'href' : $(this).attr('id'),
'href' : $(this.element).attr('id'),
This seems so simple but anytime I plug in ‘this’ or similar nothing works.
Without
each()orclick()simply add thebeforeLoadcallback to your script like thisNOTE: this is for fancybox v2.0.6+
On the other hand, a more elegant solution is to use (HTML5)
data-*attribute to set thehref(it would look weird to setid="images/01.jpg"otherwise) so you could do :and your callback
and use the
idattribute for what is meant for.EDIT : The best is to use the special
data-fancybox-hrefattribute in your anchor like :and use a simple script without callback like
See JSFIDDLE