Skip to content

allouis/deligate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Deligate

Simple event delegation

Currently only supports browsers with the Element.prototype.matches method

npm install deligate

Usage

var deligate = require('deligate');

document.body.addEventListener('click', deligate('button.some-class', function(event){
  console.log('clicked the button');
}));

// ... more likely

var handler =  deligate('button.some-class', function(event){
  console.log('clicked the button');
});

document.body.addEventListener('click', handler);

// ... later
document.body.removeEventListener('click', handler);

API

var handler = deligate(selector, fn)

Creates a function that is only called when the selector matches event.target passed to it.

About

🌟 Event delegation made easy 🌟

Resources

Stars

Watchers

Forks

Packages

No packages published