lhl 55a7808c4f create | il y a 6 mois | |
---|---|---|
.. | ||
demo | il y a 6 mois | |
dist | il y a 6 mois | |
src | il y a 6 mois | |
test | il y a 6 mois | |
.editorconfig | il y a 6 mois | |
.travis.yml | il y a 6 mois | |
karma.conf.js | il y a 6 mois | |
package.json | il y a 6 mois | |
readme.md | il y a 6 mois |
Lightweight event delegation.
You can get it on npm.
npm install delegate --save
If you're not into package management, just download a ZIP file.
var delegate = require('delegate');
<script src="dist/delegate.js"></script>
document
)delegate('.btn', 'click', function(e) {
console.log(e.delegateTarget);
}, false);
delegate(document.body, '.btn', 'click', function(e) {
console.log(e.delegateTarget);
}, false);
delegate('.container', '.btn', 'click', function(e) {
console.log(e.delegateTarget);
}, false);
delegate(document.querySelectorAll('.container'), '.btn', 'click', function(e) {
console.log(e.delegateTarget);
}, false);
var delegation = delegate(document.body, '.btn', 'click', function(e) {
console.log(e.delegateTarget);
}, false);
delegation.destroy();
Note: selectors are always treated as multiple elements, even if one or none are matched. delegate()
will return an array.
var delegations = delegate('.container', '.btn', 'click', function(e) {
console.log(e.delegateTarget);
}, false);
delegations.forEach(function (delegation) {
delegation.destroy();
});
Latest ✔ | Latest ✔ | Latest ✔ | 9+ ✔ | Latest ✔ | Latest ✔ |
MIT License © Zeno Rocha