- Listen to events of a certain type using
unmonitorEvents()to stop listening.
- Get listeners of a DOM element using
- Use the Event Listeners Inspector panel to get information on event listeners.
The monitorEvents() method instructs the DevTools to log information on the specified targets.
The first parameter is the object to monitor. All events return if the second parameter is not provided. To specify the events to listen to, pass either a string or an array of strings as the second parameter.
Listen to click events on the body of the page:
If the monitored event is a supported event type that the DevTools maps to a set of standard event names, then the method listens to the events for that type.
The Command Line API has a full mapping of event types to the events they cover.
To stop monitoring events,
unmonitorEvents() method and give it the object to stop monitoring.
Stop listening to events on the
View event listeners registered on objects
The getEventListeners() API returns the event listeners registered on the specified object.
The return value is an object that contains an array for each registered event type (
keydown, for example).
The members of each array are objects that describe
the listener registered for each type.
the following code lists all the event listeners registered on the document object:
If more than one listener is registered on the specified object,
then the array contains a member for each listener.
In the following example,
there are two event listeners registered on the #scrollingList element for the
Further expand each of these objects to explore their properties:
View event listeners registered on DOM elements
By default, the Event Listeners panel in the Elements Inspector shows all the events attached to a page:
The filter limits the events just to the selected node:
By expanding the object, the panel shows the event listener details. In this example, the page has two event listeners attached via jQuery: