Hi all

I am trying to get the following code working but somehow it doesn't..
Please help me.

------------ snip ---------

Ajax.Request('/json/images/'+query, {
    onComplete:function(xmlhttp,json)
    {
        if(json.TotalResults != 0) {
                json.Item.each(function(item)
                {
                        $('out').appendChild(
                                Builder.node('div', 
{id:item.ImgId,className:"imageResult"}, [
                                        Builder.node('img', 
{src:item.MediumImage[0].URL} ),
                                        Builder.node('p', 
item.ItemAttributes.Title )
                                ])
                        );
                        Event.observe(item.ImgId, 'click', function(e){
                                console.log('clicked '+ this.id)
                        })
                });
        } else {
               $('out').innerHTML = '<p class="notice">Nothing found</p>';
        }
    }
});

------------ /snip ---------

As you can see i am trying to create a list of images and add an
onclick event to the DIV i just built within the each loop. But it is
not working like that. I have the feeling the code doesn't even get executed..

To my understanding Event.observe shouldnt fail because I append the
element before adding the event so it should be able to find it.

If i run Event.observe after onComplete is done (takes a second) then
it works, so the code for Event.observe is fine, just on in context..

I would like to have the onComplete to do it all at once. Could
someone please help me getting this right?

TIA

-- 
Regards,
Kjell



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs
-~----------~----~----~----~------~----~------~--~---

Reply via email to