On 23 Sep 2009, at 23:27, Russell Keith wrote:

> If I am adding elements to a page after the DOM is loaded, how do I  
> add my existing Element.observe to it?

Attach them to the new element after your page update or an even  
better solution is to use event delegation.

Basically, event delegation means you put the observer on the element  
above the one you want to put behavior on. Example:


Instead of observing every <li>, you should do an event observe on the  
<ul>, then when the event fires, you can just use $(event.target) to  
see what what clicked on and handle it appropriately. If you add <li>s  
to the list, the behavior will also work on the newly inserted  
elements. You can even put the event observer on the window itself.  
Especially if you are handling a lot of elements, it's better to put  
one single event handler on the parent element than the elements  

Best regards

Peter De Berdt

You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to