Socket
Socket
Sign inDemoInstall

good-listener

Package Overview
Dependencies
1
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    good-listener

A more versatile way of adding & removing event listeners


Version published
Weekly downloads
1.3M
decreased by-17.3%
Maintainers
1
Install size
44.2 kB
Created
Weekly downloads
 

Readme

Source

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 logoEdge logoFirefox logoInternet Explorer logoOpera logoSafari logo
Latest ✔Latest ✔Latest ✔9+ ✔Latest ✔Latest ✔

License

MIT License © Zeno Rocha

Keywords

FAQs

Last updated on 28 Feb 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc