lhl 2576c8578e 1-13-1 | há 2 anos atrás | |
---|---|---|
.. | ||
demo | há 2 anos atrás | |
dist | há 2 anos atrás | |
src | há 2 anos atrás | |
test | há 2 anos atrás | |
.editorconfig | há 2 anos atrás | |
.travis.yml | há 2 anos atrás | |
karma.conf.js | há 2 anos atrás | |
package.json | há 2 anos atrás | |
readme.md | há 2 anos atrás |
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