Categories
JavaScript Answers

How to check if an element has event listener on it with JavaScript?

Spread the love

Sometimes, we want to check if an element has event listener on it with JavaScript.

In this article, we’ll look at how to check if an element has event listener on it with JavaScript.

How to check if an element has event listener on it with JavaScript?

To check if an element has event listener on it with JavaScript, we can call the getEventListeners function in the Chrome developer console.

For instance, we write

getEventListeners(document.querySelector("your-element-selector"));

in the Chrome developer console to select the element we want to check with querySelector.

And then we call getEventListeners with the element to get all the event listeners added to the element.

Conclusion

To check if an element has event listener on it with JavaScript, we can call the getEventListeners function in the Chrome developer console.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *