views:

26

answers:

0

Hello everybody,

I have a question what I try to understand for a wile.

When I am using API feed with jquery I always have a problem, it is "click", "ready" ... events, which makes me to apply some hacks or to choose another way.

For example Flickr API:

$.each(data.photoset.photo, function(i, rPhoto){
            var basePhotoURL = 'http://farm' + rPhoto.farm + '.static.flickr.com/'
                + rPhoto.server + '/' + rPhoto.id + '_' + rPhoto.secret;

            var thumbPhotoURL = basePhotoURL + '_s.jpg';
            var mediumPhotoURL = basePhotoURL + '.jpg';
            var largePhotoURL = basePhotoURL + '_b.jpg';





            var photoStringStart = '<li><a class="fancybox" rel="fncbx"';
            var photoStringEnd = 'title="' + rPhoto.title + '" href="'+
                largePhotoURL +'"><img src="' + thumbPhotoURL  + '" alt="' +
                rPhoto.title + '"/></a></li>';
                var photoString = (i < showOnPage) ?
                photoStringStart + classShown + photoStringEnd :
                photoStringStart + classHidden + photoStringEnd;


            $(photoString).appendTo(set_name);
        });

If I want to add lightbox , or fancybox. I have som trouble. Because I cannot use this kind of code

 $("a.fancybox").facybox();

or even

     $("a.fancybox").click(function(){
        alert("test");
     });

One way for me is

 $("a.fancybox").live("click" , function(){
        alert("test");
     });

All events don't work except "live" and i guess "delegate".

But if I have an alert before that "click" or another event, everything works fine (looks like the code wasn't finished and alert makes some time for pull all date from array).

I hope you can understand what I mean and if you can to explain me what happens here and if I have another options !

Thanks a lot , guys !!