Skip to content
A more versatile way of adding & removing event listeners
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
demo Fixes multiple delegates on a page sharing the same context Oct 26, 2015
dist Updates delegate package Feb 28, 2017
src Adds support for SVG elements Jan 23, 2018
test Adds support for SVG elements Jan 23, 2018
.editorconfig Adds config files Oct 25, 2015
.gitignore Adds config files Oct 25, 2015
.travis.yml Adds Travis CI Oct 25, 2015
bower.json Release v1.2.1 Dec 12, 2016
karma.conf.js Adds support for event delegation Oct 26, 2015
package.json 1.2.2 Feb 28, 2017
readme.md Updates browser support table Dec 12, 2016

readme.md

good-listener

Build Status

A more versatile way of adding & removing event listeners.

good listener

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

Chrome logo Edge logo Firefox logo Internet Explorer logo Opera logo Safari logo
Latest ✔ Latest ✔ Latest ✔ 9+ ✔ Latest ✔ Latest ✔

License

MIT License © Zeno Rocha

You can’t perform that action at this time.