Archive

Posts Tagged ‘ajax’

jQuery fancybox with ajax content.

October 1st, 2010 1 comment

There are several ways to do this I guess. What I wanted was a default css class which I could apply to an anchor tag and have a specific part of the content loaded in fancybox. This is what I came up with. It is also possible to do this with the ajax property of fancybox itself I suppose.

$(function () {
    $("a.ajaxcontent").click(
        function (event) {
            event.preventDefault();
            var url = jQuery(this).attr("href");
 
            $.get(
                url,
                function (data) {
                    var content = jQuery(data).find("#content");
                    $.fancybox(content);
                }
            );
        }
    );
});
Categories: jQuery Tags: , ,