delegate

WebJar for delegate

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

delegate
Last Version

Last Version

3.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

delegate
WebJar for delegate
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/zenorocha/delegate

Download delegate

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/delegate/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>delegate</artifactId>
    <version>3.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/delegate/
implementation 'org.webjars.npm:delegate:3.2.0'
// https://jarcasting.com/artifacts/org.webjars.npm/delegate/
implementation ("org.webjars.npm:delegate:3.2.0")
'org.webjars.npm:delegate:jar:3.2.0'
<dependency org="org.webjars.npm" name="delegate" rev="3.2.0">
  <artifact name="delegate" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='delegate', version='3.2.0')
)
libraryDependencies += "org.webjars.npm" % "delegate" % "3.2.0"
[org.webjars.npm/delegate "3.2.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

delegate

Lightweight event delegation.

Install

You can get it on npm.

npm install delegate --save

If you're not into package management, just download a ZIP file.

Setup

Node (Browserify)
var delegate = require('delegate');
Browser (Standalone)
<script src="dist/delegate.js"></script>

Usage

Add event delegation

With the default base (document)

delegate('.btn', 'click', function(e) {
    console.log(e.delegateTarget);
}, false);

With an element as base

delegate(document.body, '.btn', 'click', function(e) {
    console.log(e.delegateTarget);
}, false);

With a selector (of existing elements) as base

delegate('.container', '.btn', 'click', function(e) {
    console.log(e.delegateTarget);
}, false);

With an array/array-like of elements as base

delegate(document.querySelectorAll('.container'), '.btn', 'click', function(e) {
    console.log(e.delegateTarget);
}, false);

Remove event delegation

With a single base element (default or specified)

var delegation = delegate(document.body, '.btn', 'click', function(e) {
    console.log(e.delegateTarget);
}, false);

delegation.destroy();

With multiple elements (via selector or array)

Note: selectors are always treated as multiple elements, even if one or none are matched. delegate() will return an array.

var delegations = delegate('.container', '.btn', 'click', function(e) {
    console.log(e.delegateTarget);
}, false);

delegations.forEach(function (delegation) {
    delegation.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

Versions

Version
3.2.0
3.1.2