PinoyTech.org

CodeIgniter, Kohana, Mootools, jQuery and CSS

Implementing jQuery Live in Mootools

Posted by teejay on March 8, 2010

If you're like me, I've been wanting to have a jquery live implementation in Mootools for the longest time. Luckily someone from Stackoverflow did it for us.

It's not exactly jQuery Live but it is quite useful and I've used it one some personal project I have. Here's the code:

Code:

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));
    }
});

Usage:

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

Categories: Web Development, Clientside

Tags: jquery, mootools

No Comments

Comments are not allowed