You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
11 months ago | |
|---|---|---|
| .. | ||
| demo | 11 months ago | |
| dist | 11 months ago | |
| src | 11 months ago | |
| test | 11 months ago | |
| .editorconfig | 11 months ago | |
| .npmignore | 11 months ago | |
| .travis.yml | 11 months ago | |
| bower.json | 11 months ago | |
| karma.conf.js | 11 months ago | |
| package.json | 11 months ago | |
| readme.md | 11 months ago | |
readme.md
good-listener
A more versatile way of adding & removing event listeners.
Install
You can get it on npm.
npm install good-listener --save
Or bower, too.
bower install good-listener --save
If you're not into package management, just download a ZIP file.
Setup
Node (Browserify)
var listen = require('good-listener');
Browser (Standalone)
<script src="dist/good-listener.js"></script>
Usage
Add an event listener
By passing a string selector (see full demo).
listen('.btn', 'click', function(e) {
console.log(e);
});
Or by passing a HTML element (see full demo).
var logo = document.getElementById('logo');
listen(logo, 'click', function(e) {
console.log(e);
});
Or by passing a list of HTML elements (see full demo).
var anchors = document.querySelectorAll('a');
listen(anchors, 'click', function(e) {
console.log(e);
});
Remove an event listener
By calling the destroy function that returned from previous operation (see full demo).
var listener = listen('.btn', 'click', function(e) {
console.log(e);
});
listener.destroy();
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|---|---|
| Latest ✔ | Latest ✔ | Latest ✔ | 9+ ✔ | Latest ✔ | Latest ✔ |
License
MIT License © Zeno Rocha






