"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How Can I Use Chrome DevTools to View Events Fired on Elements?

How Can I Use Chrome DevTools to View Events Fired on Elements?

Published on 2024-11-23
Browse:386

How Can I Use Chrome DevTools to View Events Fired on Elements?

Viewing Events Fired on Elements with Chrome DevTools

To troubleshoot and optimize event handling on your web pages, you can use Chrome DevTools to inspect the events triggered on specific elements.

Execute the following steps using Chrome Web Developer:

  1. Inspect the Element:

    • Right-click on the target element and select "Inspect" or navigate to the "Elements" tab in DevTools.
  2. Monitor Events:

    • Using monitorEvents:

      • Open the "Console" tab.
      • Enter monitorEvents($0) in the console, where $0 represents the selected element.
    • Specifying Event Type:

      • Optionally, provide the event type you want to monitor as a second argument to monitorEvents, e.g., monitorEvents(document.body, 'mouse').

Interactions with the inspected element will now display their event names and associated data.

  1. Stop Monitoring:

    • To discontinue event monitoring, enter unmonitorEvents($0) in the console.

Available Event Types (as of 2023-01-30)

You can narrow down monitored events by specifying the following types:

  • mouse: mouse events (down, up, click, etc.)
  • key: keyboard events (down, up, press, etc.)
  • touch: touch events (start, move, end, etc.)
  • control: element control events (resize, focus, change, etc.)
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3