Element.Delegates 0.2
This extension is a another fresh look at event delegation. No addEvent('relay(a)',fn) kind of things, but a more simple API
Details
- Author
- Arian Stolwijk
- Current version
- 0.2
- GitHub
- arian/Element.Delegation
- Downloads
- 2858
- Category
- Native
- Tags
- Report
- GitHub Issues
How to use
This is the most simple example how you can use this Element.Delegation
document.body.addDelegate('click','a',function(){
// do it!
});
More advanced Selector example
document.id('myElement').addDelegate('click','a[href^=mailto:]',function(){
// so you want to mail someone ?
});
More delegates
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
}
}
});
Remove delegates
var fn = function(){};
document.id('myElement').addDelegate('click','a',fn);
document.id('myElement').removeDelegate('click','a',fn);
Remove more than one at the time
var fn = function(){};
document.id('myElement').addDelegate('click','a',fn);
document.id('myElement').removeDelegate({
'click': {
'a': fn
}
});
Add delegates to a new Element
new Element('div',{
delegates: {
'click': {
'input:checked': function(e){
// Your code
}
}
}
});
Discuss
A note on comments here: These comments are moderated. No comments will show up until they are approved. Comments that are not productive (i.e. inflammatory, rude, etc) will not be approved.
Found a bug in this plugin? Please report it this repository's Github Issues.
blog comments powered by Disqus