views:

228

answers:

0
Element.implement({
    addLiveEvent: function(event, selector, fn){
        this.addEvent(event, function(e){
            var t = $(e.target);

            if (!t.match(selector)) return false;
                fn.apply(t, [e]);
        }.bindWithEvent(this, selector, fn));
    }
});

$(document.body).addLiveEvent('click', 'a', function(e){ alert('This is a live event'); });

The above code was done in a similar question to implement .live behaviour in Mootools. I've read the question: http://stackoverflow.com/questions/1479782/prototype-equivalent-for-jquery-live-function.

How do I implement this in Prototype? Probably something that can be implemented like this:

document.liveobserve('click', 'a', function(e){ alert('This is a live event');

Edited to make the question clear.