npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

geteventlisteners

v1.1.0

Published

getEventListeners() : Returns an object containing all the event listeners of a DOM Node.

Downloads

2,344

Readme

Element.prototype.getEventListeners()

Returns the event listeners registered on the specified object. The return value is an object that contains an array for each registered event type (click or keydown, for example). The members of each array are objects that describe the listener registered for each type.

A simple usage example :

    let myEl = document.getElementById('someElementId');
    // add some event listeners to the Element
    myEl.addEventListener('click', e=> console.log('click!') );
    myEl.addEventListener('click', e=> console.log('click 2!') );
    myEl.addEventListener('mouseover', e=> console.log('mouse over!') );

    // retrieve the listeners
    console.log( myEl.getEventListeners() );
    /*
    { 
    	click : [
		{ listener: ƒ, useCapture: false, type:"click"},
		{ listener: ƒ, useCapture: false, type:"click"}
        ],
	mouseover : [
		{ listener: ƒ, useCapture: false, type:"mouseover"}
	]
    }
    */

Retrieve only the click-event listeners :

    console.log( myEl.getEventListeners('click') );
    /*
    [
        { listener: ƒ, useCapture: false, type:"click"},
        { listener: ƒ, useCapture: false, type:"click"}
    ]
    */

Package distribution :

You can include this library using the CDN ...

<script src='https://cdn.jsdelivr.net/gh/colxi/getEventListeners/src/getEventListeners.min.js'></script>

Package can also be installed via:

$ npm install geteventlisteners --save

and is also available in Github :

https://github.com/colxi/getEventListeners

Limitations

To be able to track the event listeners assignements, this module overwrites Element.prototype.addEventListener and Element.prototype.removeEventListener, with custom functions that mantain an updated list of listeners. Any event listener declared before this module is imported will be missed.

In order to be able to track all the listeners, this module must be imported before any event listener is declared.

Only event listeners declared using Element.addEventListener(), are going to be tracked. For example, the following event listeners declarations, will not be tracked :

<div onclick="myFunction()"></div>

and...

myElement.onclick= function(){ /*your code*/ }