This extension is a another fresh look at event delegation. No addEvent('relay(a)',fn) kind of things, but a more simple API
This is the most simple example how you can use this Element.Delegation
#JS
document.body.addDelegate('click','a',function(){
// do it!
});
#JS
document.id('myElement').addDelegate('click','a[href^=mailto:]',function(){
// so you want to mail someone ?
});
#JS
document.id('myElement').addDelegates({
'click': {
'a[href^=mailto:]': function(){
// so you want to mail someone ?
},
'a[a.email]': function(){
// Do something else
}
},
'mouseover': {
'p': function(){
// You hovered a paragraph
}
}
});
#JS
var fn = function(){};
document.id('myElement').addDelegate('click','a',fn);
document.id('myElement').removeDelegate('click','a',fn);
#JS
var fn = function(){};
document.id('myElement').addDelegate('click','a',fn);
document.id('myElement').removeDelegate({
'click': {
'a': fn
}
});
#JS
new Element('div',{
delegates: {
'click': {
'input:checked': function(e){
// Your code
}
}
}
});