I believe the `e.element()` line should use `Event#findElement`  
instead to walk the DOM tree up to find the first parent matching.

   document.observe('click', function(e) {
     if (e.findElement('.test')) {

I think it's definitely worth the effort, I've been personnally using  
this pattern successfully in many applications.
In previous discussions, we ended up with the following signature:

  `Element.delegate(@element, selector, eventName, callback)`

Then jQuery's `.live` query :

   `$(selector).live(eventName, callback);

would become:

   document.delegate(selector, eventName, callback);

IMO it should definitely be part of the framework.


On 28 mai 09, at 03:31, Josh Powell wrote:

> $(document).observe('click',  function (e) {
>    if (e.element().match('.test')) {
>        console.log('clicked');
>    }
> });
> Ok, that's not tested.  The e.element() line is probably wrong, but it
> accomplishes what .live() in jQuery does.  You set an event handler on
> the document, which all events filter up to, and then check to see if
> the element that bubbled up the event matches your selector and
> execute your code if it does.
> Josh Powell
> On May 27, 5:46 pm, Luisgo <> wrote:
>> I have thought about creating an extension for prototype to emulate
>> JQuery's ".live" behavior but, it not being available makes me think
>> that maybe it's not possible or worth the effort.
>> I know how to apply behaviors after changing the DOM but no one can
>> deny .live is very handy.
>> 1. Any thoughts on this?
>> 2. Has anyone tried to implement it?
>> 3. Can I help?
>> 4. How would you implement it?
>> I thought about extending both the selector (to keep an array of
>> executed queries/CSS selectors) and Ajax.Request but this would not
>> cover elements added dynamically that are NOT loaded through ajax.
>> Thanks
> >

You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Reply via email to