Every jquery method includes an optional callback that you can explicitly
call:

$('#photoholder').append(imgdiv, function(){
        // do something here
});

-----Original Message-----
From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of karlo_ubc
Sent: Monday, June 09, 2008 3:54 PM
To: jQuery (English)
Subject: [jQuery] passings variables to callback functions


I was wondering if there are ways to pass variables of non-global scope to
callback function like in the situation below. I've run into this situation
before and imagine it comes up often. So passing the photo[i]['id'] variable
to imgselect is the issue here since at the time the event is triggered, it
does not have the same value as it would at the time of binding.

for (i=0;i<photo.length;i++) {
   var newimg = document.createElement('img');
   $(newimg).attr('src',photo[i]['url']);
   $(newimg).bind("click", imgselect(photo[i]['id']));

   $('#photoholder').append(imgdiv);
}


Reply via email to