Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dom-event-listener

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dom-event-listener

Cross browser event listeners

  • 1.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

dom-event-listener

Cross-browser event listeners made out of the box.

Installation

Just get it from the npm.

npm i dom-event-listener --save

Setup

Browserify
var domEventListener = require('dom-event-listener');
ES6
import domEventListener from 'dom-event-listener';

Usage

Adding an event listener

import domEventListener from 'dom-event-listener';

let element = document.getElementById('my-element');

domEventListener.add(element, 'click', (event) => {
    console.log(event);
});

Removing an event listener

import domEventListener from 'dom-event-listener';

let element = document.getElementById('my-element');

function onClick(event) {
  console.log(event);
}

domEventListener.add(element, 'click', onClick);
domEventListener.remove(element, 'click', onClick);

Fancy keeping your scope?

Pass an object with a handleEvent function.

import domEventListener from 'dom-event-listener';

let element = document.getElementById('my-element');

let object = {
  value: 'some random value',
  handleEvent: function (event) {
    console.log(this.value);
    console.log(event);
  }
};

domEventListener.add(element, 'click', object);
domEventListener.remove(element, 'click', object);

The event object

Getting cross browser properties:

currentTarget
var element = event.currentTarget;
target
var element = event.target;
preventDefault
event.preventDefault();

Browser Support

Chrome logoFirefox logoInternet Explorer logoOpera logoSafari logo
Latest ✔Latest ✔IE 8+ ✔Latest ✔Latest ✔

License

[MIT License] © Florian Barbare

Keywords

FAQs

Package last updated on 27 Jun 2016

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc