2

Is there a way to assign a multiple event types in MooTools like jQuery?

Mootools:
$$('#id').addEvents({
    keyup: fn,
    click: fn
});

jQuery:
$('#id).bind('keyup click' ,fn);

2 Answers 2

2

Yes, there is a way, through the powerful implement:

Element.implement({
    fakeBind : function(evtsStr, callback){
        var events = evtsStr.split(' '), 
            i = 0, 
            l = events.length;
        for (; i < l; i++){
            this.addEvent(events[i], callback);
        }
    }
});

$$('div.myClass').fakeBind('click mouseleave', function(event){
    console.log(event.type);
});

Demo

2
  • That is ugly API for adding events. One of the reasons I can't stand jQuery, the API is illogical. Commented Jul 21, 2011 at 10:07
  • I absolutely agree with you :), however, the powerful of mootools is that it's easy to 'simulate' jQuery's API ugliness! :D
    – stecb
    Commented Jul 21, 2011 at 10:15
1

Its not much, but have a look at this: http://ryanflorence.com/jquery-1-4-mootools-1-2-compared/#binding-multiple-events

In this article Jquery 1.4 and mootools 1.2 are compared, and they really look alike..

Im afraid i can't think of any way that mootools can do that..

Not the answer you're looking for? Browse other questions tagged or ask your own question.