Activate onclick for prepended element?
In the midst of a large image-upload routine, I have a system where an image gets uploaded, then a thumbnail of the image is added to an existing <ul> structure where each <li> contains an image.
In other words, there are a bunch of images, and when I upload one, I insert another as a new <li> at the beginning of the list. This is all working great.
However ... I also have a function defined in the head of the page where any image in the list that is clicked causes the source of a larger image to change. This also works great - except after my new image is prepended to the lsit, the onclick does not work for that image. all of the other images in the list continue to work as expected onclick, but the new one is not effected.
i am assuming this is because the function was already called when the page loaded the first time, setting a 'listener' on each existing image - so, how can I 'reset' the function, so that it will 'listen' for a click on the new image?
Since the image upload is using ajax, I can call anything I want as part of the 'success' routine. What I need is a line in this success script that says "reindex the list of images and reapply the 'onclick' function to them all'... or something like that...
any ideas??