
Product
Introducing Supply Chain Attack Campaigns Tracking in the Socket Dashboard
Campaign-level threat intelligence in Socket now shows when active supply chain attacks affect your repositories and packages.
Handle events on elements
npm install handle
handle(element, event, fn [, capture])Handle event on element using fn. It returns a function that can be called to stop listening. e.g. to build once you could write:
var handle = require('handle');
function once(element, event, fn, capture) {
var dispose = handle(element, event, function (el, event) {
dispose();
fn(el, event);
}, capture);
}
Typical usage might look like:
var handle = require('handle');
handle(document.getElementById('my-button'), 'click', function (button, e) {
e.preventDefault();
// do something
});
handle(elements, event, fn [, capture])You can handle the same event on a whole list of elements in one go. This does not need to be an array, it just needs to have a .length property that is a number and have indexed values. e.g.
var handle = require('handle');
handle(document.querySelector('[data-action="do-something"]'), 'click', function (button, e) {
e.preventDefault();
// do something
});
It too returns a dispose funciton.
handle(selector, event, fn [, capture])This works just like jQuery's $(document.body).delecate(selector, event, function (e) { fn(this, e) }). It too returns a dispose function.
The advantages/disadvantages of using this method are:
handle is called.e.g.
var handle = require('handle');
handle('[data-action="do-something"]', 'click', function (button, e) {
e.preventDefault();
// do something
});
If you want to delegate from something other than document.body you can select a start element via the .on method:
var handle = require('handle').on(document.getElementById('hideable-list'));
handle('li', 'click', function (li, e) {
e.preventDefault();
li.style.visibility = 'hidden';
});
Tests can be easilly run locally in the browser of your choice, and have passed if it ends with # ok. They are also run on testling-ci when pushed to the repository:
npm install
npm test
MIT
FAQs
Handle events on elements
The npm package handle receives a total of 148 weekly downloads. As such, handle popularity was classified as not popular.
We found that handle demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.

Product
Campaign-level threat intelligence in Socket now shows when active supply chain attacks affect your repositories and packages.

Research
Malicious PyPI package sympy-dev targets SymPy users, a Python symbolic math library with 85 million monthly downloads.

Security News
Node.js 25.4.0 makes require(esm) stable, formalizing CommonJS and ESM compatibility across supported Node versions.