Hi, this question is more likely to be advice on best practice. Sometimes, when I create a full ajax application, I usually add elements dynamically, for example. When you add a list of elements, I do something like:
var template = new Template("<li id='list#{id}'>#{value}</li>");
var arrayTemplate = [];
arrayOfItem.each(function(item, index){
arrayTemplate.push(template.evaluate( id : index, value : item))
});
after these two options add the list via "update" or "paste"
----- $("elementToUpdate").update("<ul>" + arrayTemplate.join("") + "</ul">);
question
how can I add an event handler without repeating the process of reading the array, because if you try to add an event before updating or pasting, you will receive an error message because the element is not yet in the DOM.
so what i am doing so far after insert or update:
arrayOfItem.each(function(item, index){
$("list" + index).observe("click", function(){
alert("I see the world");
})
});
so the question is, is there a better way to do this ??????