Implementing jQuery Live in Mootools
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
No Comments