← Back toFront-end Tips

Inspect an element shown on hover

Written byPhuoc Nguyen
01 Mar, 2021
To inspect an element with Chrome DevTools, we usually right-click the element and choose Inspect from the context menu. However, it doesn't work with a dynamic element that is displayed when we hover on a given element. A JavaScript tooltip is a common example.
There are a few ways to inspect that kind of elements.

Trigger the mouseover event

  • Right-click the original element, and choose the Inspect menu item
  • Click the Console tab
  • Fire the `mouseover` event by excuting the following code in the Console:
new MouseEvent('mouseover', {
view: window,
bubbles: true,
cancelable: true,
`$0` represents the current inspected element
It simulates the `mouseover` event that is supposed to happen when we hover on the original element.

Pause the script execution

  • Open the Chrome Developer Tools, and click the Sources tab
  • Hover on the target element, and click the F8 key
  • Move the mouse over the target element
  • Activate the Elements tab, and you will see the dynamic element shown up here

Use debugger

It's similar to the previous way.
  • In the Console, execute the following code:
handler = (e) => {
if (e.key === 'Enter') debugger;
document.addEventListener('keydown', handler);
Running `debugger` here will pause the script execution when we press the Enter key. Of course, you can replace it with other key.
  • Hover on the target element, and click the Enter key
  • The dynamic element is displayed and visible under the Elements tab
Once you don't want to monitor the dynamic element anymore, you can stop listening to the `keydown` event:
document.removeEventListener('keydown', handler);

Track subtree modifications

  • Open the Chrome Developer Tools, and click the Elements tab
  • Right-click the `body` element, and choose Break on > subtree modifications from the context menu
Break on subtree modifications
Break on subtree modifications
If the dynamic element, a tooltip for example, is generated in the parent element of the target element, then you should choose the parent instead of the `body` element
  • Move the mouse over the target element
  • You will see the dynamic element shown in the Elements tab

Questions? 🙋

Do you have any questions? Not just about this specific post, but about any topic in front-end development that you'd like to learn more about? If so, feel free to send me a message on Twitter or send me an email. You can find them at the bottom of this page.
I have a long list of upcoming posts, but your questions or ideas for the next one will be my top priority. Let's learn together! Sharing knowledge is the best way to grow 🥷.

Recent posts ⚡

Newsletter 🔔

If you're into front-end technologies and you want to see more of the content I'm creating, then you might want to consider subscribing to my newsletter.
By subscribing, you'll be the first to know about new articles, products, and exclusive promotions.
Don't worry, I won't spam you. And if you ever change your mind, you can unsubscribe at any time.
Phước Nguyễn