Skip to content

patrickpietens/addlistener.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

addlistener.js

Helper functions for adding and removing listeners to Node and NodeList objects. Adds on, off and once methods to the Node, NodeList and window prototypes.

Installation

$ npm install --save addlistener.js

Example

import 'addlistener.js';

// Adding a click listener to element myFoobar
let myElement = document.getElementById('#foobar');
const removeClickListener = myElement.on('click', (event) => { ... });

// The addListener returns a functions which remove the listener when invoked:
removeClickListener();

// Futhermore, you can use the on, off and once on element(s):
let myElements = document.querySelectorAll('.foobar');
myElements.once('click' (event) => { ... });

// And on the window object
window.on('resize', (event) => { ... });

About

Helper functions for adding and removing listeners to Node and NodeList objects

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published