Home > jQuery > jQuery fancybox with ajax content.

jQuery fancybox with ajax content.

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: , ,
  1. suraj
    November 20th, 2011 at 07:37 | #1

    thnxs ..helped me a lot !!!

  1. No trackbacks yet.

Time limit is exhausted. Please reload CAPTCHA.