Event Pseudo: n-times

Fire an event n times and then stop.

HTML

<button id=click-me>click me</button>
<h1>I will highlight 3 times</h1>

JavaScript

Event.definePseudo('n-times', function(split, fn, args){
    if (!fn.count) fn.count = 0;
    fn.apply(this, args);
    if (++fn.count == split.value) this.removeEvent(split.original, fn);
});

$('click-me').addEvent("click:n-times(3)", function(){
    $$('h1').highlight();
});