Explain Codes LogoExplain Codes Logo

Inspect hovered element in Chrome?

web-development
prompt-engineering
best-practices
responsive-design
Alex KataevbyAlex Kataev·Jan 15, 2025
TLDR

Instantly explore a hovered element in Chrome using Ctrl+Shift+C (Cmd+Shift+C on Mac), then hover over the intended item. To freeze the :hover state for examination, launch Developer Tools, locate the item in the Elements panel, right-click, go to the :hov menu, and opt for :hover. The item now persists in a hover state for a thorough study and modification of styles.

Inspect dynamic elements like a Pro

Fetching certain dynamic elements like tooltips can be challenging. This guide will help you step up your inspection game:

  1. Hover over the dynamic element: Position your mouse cursor over the targeted element.
  2. Launch Developer Tools: Press F12 (PC) or Cmd+Opt+I (Mac) to fire up Chrome's DevTools.
  3. Pause script execution:
    • While continuing to hover, press F8 to freeze the active script.
    • Alternatively, jump to the Sources tab and manually set a breakpoint, or trigger the debugger; statement in the Console.
  4. Inspect the frozen element: With the webpage paused, visit the Elements tab and inspect the element at your leisure.

Going the extra mile

Dealing with complex tooltips

  • Bootstrap tooltips: If you're dealing with tooltips powered by Bootstrap, key in $('[data-toggle="tooltip"]').tooltip('show') into the console to encourage the tooltip to show up.
  • $0 Console Shortcut: In Chrome's console, $0 refers to the previously inspected element. So, you can use $($0).tooltip('show') to expose the tooltip of a recently inspected item.
  • Unleashing Console: Boost your inspection capabilities by launching the console in its own window. You can toggle this in the DevTools settings.

Keeping pace with dynamic content

When dealing with rapidly changing content, employ these advanced pausing techniques:

  • JavaScript Breakpoints: Temporarily include setTimeout(() => {debugger}, 5000) in your script, hover over the element, and wait for the debugger to pause the execution.
  • Quick Console Switch: If you are toggling frequently between elements and console, the `Ctrl+`` shortcut allows the switching of focus to the console without a mouse.

Morse code in CSS

Once you've paused execution at the desired state:

  • Inspect the CSS directly under the Sources tab. This provides more insights into styles applied via JavaScript.
  • Alternatively, visit the Elements tab to analyze the structure and styling of the tooltip.
  • If the tooltip doesn't persist, manually toggle the :hover state in the Styles pane.

Exceptional inspection: Pro tips

Perfecting the Pause

Toothlessly fighting with the misfired pause, where it halts at the wrong moment? No worries:

  • Practice is Key: Strive to practice the pause technique. With repetition, the speed to mastering comes.
  • Auditory Cues: If your application produces an accompanying sound when the tooltip gets displayed, synchronize your pause with this auditory cue.

Troubleshooting toolbox

Troubles inspecting? Fear not:

  • Overrides: Make sure a CSS override isn't hiding your tooltip. Have a look in the Styles pane.
  • Z-Index Issues: If the tooltip is hiding behind another element, bring it up using the z-index property.
  • Browser Extensions: Switch off any browser extensions that might interfere with DevTools.

Documentation: Future Self will Thank You

  • Snapshots: Use the Capture node screenshot feature in DevTools to document the element's state for future reference.
  • Code Snippets: Save your JavaScript snippets in the Sources tab for future usage.