JulianJ JulianJ - 1 month ago 6
jQuery Question

Where should I add afterLoad to some jquery code

I'm trying to add a piece of javascript to a fancybox image but I'm not sure the correct place to put it. I'd really appreciate it if someone could show me where to add this :

afterLoad: function () {
this.outer.append("Read More");
}


to this code:

$(document).ready(function() {
$("#single_image").fancybox({

afterShow: function () {
$(".fancybox-image").wrap($("<a />", {
href: this.href, //or your target link
target: "_blank"
}));
event.preventDefault();
}

});

});


I've made a fiddle here

Answer

Simply add it to the options being passed to fancybox:

$("#single_image").fancybox({
    afterShow: function () { /.../ },
    afterLoad: function () { /.../ }
});
Comments