views:

342

answers:

1

Hello,

I have implemented lightbox-plugin for jQuery of krewenki in a masterpage including all images. This was working fine. Till i put the images in a external page and load this external images page in the master document. Lightbox does not work anymore. Is this jQuery code fault, or is this a lightbox-plugin problem?

Main-html

<html>
<head>
    <link rel="stylesheet" type="text/css" href="css/jquery.lightbox.css" />
    <script src="js/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="js/jquery-ui-1.7.2.custom.min.js" type="text/javascript"></script>
    <script src="js/jquery.lightbox.js" type="text/javascript"></script>
    <!-- http://github.com/krewenki/jquery-lightbox  -->
    <script language="JavaScript">
        jQuery(document).ready(function() {
            $("#loadimages").live('click', function() {
                $('#images').load('images.html');

                $(".lightbox").lightbox(); // THIS DOESN'T WORK???
            }       
        });
    </script>
</head>
<body>
    <div><a href="#" id="loadimages">Load images</a></div>
    <div id="images"></div>
</body>
</html>

images.html

<a href="image1.jpg" class="lightbox" rel="group1" title="image1"><img src="imgage1_thumb.jpg"/></a>
<a href="image2.jpg" class="lightbox" rel="group1" title="image2"><img src="imgage2_thumb.jpg"/></a>
<a href="image3.jpg" class="lightbox" rel="group2" title="image3"><img src="imgage3_thumb.jpg"/></a>
<a href="image4.jpg" class="lightbox" rel="group2" title="image4"><img src="imgage4_thumb.jpg"/></a>
+2  A: 

You are not waiting for load() to finish before calling lightbox(). It is an asynchronous function, so you have to do it through a callback:

jQuery(document).ready(function() {
    $("#loadimages").live('click', function() {
        $('#images').load('images.html', function() {
            $(".lightbox").lightbox();
        });
    }       
});
Max Shawabkeh
Ok, this part i was still missing, the callback! This is geat and works perfect. Thanks for this lesson! Now i can fix al my other bugs :-) Thanks!
Guido Lemmens 2