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.