Sometimes, we want to find event listeners on a DOM node using JavaScript.
in this article, we’ll look at how to find event listeners on a DOM node using JavaScript.
How to find event listeners on a DOM node using JavaScript?
To find event listeners on a DOM node using JavaScript, we can use the getEventListeners
function in the Google Chrome dev console.
For instance, we run:
getEventListeners(document.body)
to return all the event listeners added for the body element.
Then we get something like:
{
"click": [
{
"useCapture": false,
"passive": false,
"once": false,
"type": "click"
}
]
}
from the console log.
Conclusion
To find event listeners on a DOM node using JavaScript, we can use the getEventListeners
function in the Google Chrome dev console.