you have the general concept down. if you had a list element (ul) with a
bunch of list items (li) and you added this delegation method:

myUL.addEvent('click:relay(li)', function(event, element) { alert("you
clicked " + element.get('id')) });

Then, if you added any new list item to the list it would get this behavior.
This is one of the benefits of delegation. If you wanted to prevent this
from occurring to some of the list items you might give them all a class and
delegate only to those with the class assigned, removing the class from
those you don't want to have the behavior.

You can't prevent this behavior by attaching an event or calling removeEvent
on the li objects, as they don't have events attached to them.

On Mon, Nov 23, 2009 at 4:10 AM, Rolf -nl <[email protected]> wrote:

> If I add an event to a collection of elements in a parent using event
> delegation that it automatically also adds the event on new elements
> created in that parent?
> From tests I can say this is true, and I think it's also in the docs
> "[..] evaluating your code only when the user actually clicks [..]"
> but just to make sure... Correct?!
>
> I used to have attach/detach methods in several classes that I would
> run on each element in a collection of elements which aren't needed
> anymore if I do one addEvent on a parent container using event
> delegation...
>
> One more thought (not tested yet).. if I would do a removeEvent on a
> single element in the collection of elements (aka to temporary "lock"
> a drag/drop possibility by removing the event), is this going to work
> if I earlier added the event with event delegation to the parent?
>

Reply via email to