"Inspect" a hover element?
Asked Answered
I

12

196

Note: I've read similar threads, but none quite my issue - I can right click on it fine, it just then disappears.

I find 'Inspect Element' an invaluable tool in Chrome, however I'm having trouble using it for sub-menu for an element on my nav bar, which pops up below on hover of its parent item.

The popup (or down) isn't quite styled how I'd like, so I right-click > inspect element to see what's coming from where exactly, and get a better idea of how to achieve my desired effect.

However, as soon as I move my mouse away from the menu, it's gone; thus I can't select different elements in the inspection pane, and see which area is highlighted at the same time.


Is there a way around this, without changing the menu, so that it stays 'popped up' once activated?

Inhabit answered 11/7, 2013 at 20:14 Comment(2)
In situations like this, I usually use the console to make a temporary modification to the page, such as removing the mouseleave event from the parent menu. The sub-menu should then stay open even after you move your mouse off of the parent menu.Burette
Chrome supports this now. Select the UI element (e.g. a tag) > Inspect Element > Styles Tab, next to the filter box there is a ":hov" section. Click it. Now you can select hover checkbox and see what styles loads on hover.Mariomariology
B
318

This answer assumes that the hover element is triggered by JavaScript. If it is triggered via the CSS :hover pseudo-class, see gmo's answer.


You can inspect JavaScript-based hover elements if you pause JavaScript execution while the hover element is visible. This can be accomplished in one of the following ways:

1. Via a keyboard shortcut

Here's how you do it in Chrome. I'm sure Firefox has an equivalent procedure:

  1. Open up Developer Tools and go to Sources.

  2. Note the shortcut to pause script execution—F8 (there may also be another depending on your OS).

    Pause script execution

  3. Interact with the UI to get the element to appear.

  4. Hit F8.

  5. Now you can move your mouse around or inspect the DOM, as needed. The element will stay there.

2. Via a delayed debugger statement

Some web pages attach keydown / keypress / keyup event listeners which interfere with the shortcut above. In those cases, you can pause script execution by triggering a breakpoint via a delayed debugger statement:

  1. Open the JS console, and enter:

    // Pause script execution in 5 seconds
    setTimeout(() => { debugger; }, 5000)
    
  2. Trigger the hover and wait for the debugger statement to execute.

Barrack answered 5/8, 2016 at 7:8 Comment(13)
The other methods offered here don't work in a lot of contexts where this does.Pokeweed
Perfect. For some reason F8 didn't work before I found this post. Now I tried it again on the same page I'm diagnosing, and it worked. (cwl)Dunois
for Safari it's Debugger tabPriming
It didn't work for me. After F8, the screen freezes and can't select any elements. My workaround is to press F8, the switch to the Elements tab, then search for the words that are on the hover element.Propositus
Like AngryHacker, I noticed that the "select an element" icon isn't selectable after pressing F8. But the HTML is searchable, and also clickable. Very appreciative of mxk and Bhuwan's answer!Behre
This isn't working in Chrome. Per @Propositus the website can't be interacted with via the mouse script execution is paused. You can't left or right click on anything on the web page.Varicelloid
This saved me thank you! For those saying they can't interact with the page, I just dug through the Elements tab to find what I needed - granted I was dealing with css which does still change!Elwin
Used this to debug a drag previewApplewhite
It works the same on Firefox but you need to have the focus in the debugger tab before pressing F8 (that shortcut works from there). Once paused, you can inspect the DOM with all the elements that only exist during an :hover state being present. It's just a question on pressing F8 while hovering the elements to inspect. If you need to select another element, try to avoid the contextual menu to inspect (can trigger unpause). Use the top left icon of the devtool to capture it.Add
In Chrome, to inspect an element in debug mode, click the first icon (inspect element) in chrome dev tools (Shortcut is Ctrl + Shift + C).Hamelin
This looks useful but unfortunately didn't seem to help with the hover effects within an SVG in MapMyRun.com.Nitty
you must have the SOURCES tab be open for this to work... easy to miss that bitSites
@Nitty for the SVG hover, it sounds like it might be using CSS-based hover, for which you can see gmo's answer: https://mcmap.net/q/103124/-quot-inspect-quot-a-hover-element.Barrack
A
92

If the hover effect is given with CSS then yes, I normally use two options to get this:

One, to see the hover effect when the mouse leave the hover area:
Open the inspector in docked window and increase the width until reach your HTML element, then right click and the popup menu must be over the inspector zone... then when you move the mouse over the inspector view, the hover effect keep activated in the document.

enter image description here

Two, to keep the hover effect even if the mouse is not over the HTML element, open the inspector, go to Styles TAB and click in the upper right icon that says Toggle Element State...(dotted rectangle with an arrow) There you can manually activate the Hover Event (among others) with the checkbox provided.

enter image description here

If it's not clear at all, let me know and I can add a few screenshots. Edited: screenshot added.

And finally and as I say at the begining, I only be able to do this if the hover is set with CSS:HOVER... when you control the hover state with jQuery.onMouseOver for example, only works (sometimes), the method One.

Hope it helps.

Arcograph answered 11/7, 2013 at 20:44 Comment(4)
Your first solution is a good workaround, and I have a way to make it better: right click the hovered element, move the mouse completely away to the "inspector zone", and then navigate with the keyboard keys and hit enter on "inspect element". The element will be kept hovered. As for your second solution, yeah, that (or using the context menu's :hover) should obviously have been the correct solution, but very unfortunately this hasn't worked on Chrome/Firefox for as long as I can remember...Thrive
I was used to doing this in Windows, but in Mac this trick doesn't work, has anybody found a way to this on a mac? it seems it "communicates" mouse move events to the window even if the mouse is in the inspector or sub-menuPhenol
@GiladBarner thank you for your offered shortcut, it worked for me. I don't know if this is just a problem on my PC or not, but I can't see the menu option selected via keyboard and the shortcut key (ctrl-shift-I) doesn't work while the dropdown menu is visible, so since inspect element is the last option on the dropdown, I used up-arrow key to wrap-around to the last item and hit enter, and it worked.Williamson
Seems like at moment the :hover option is in Toggle Classes OptionDermatophyte
C
58

What worked for me is selecting the specific a tag I wanted to inspect and configure it to break on attribute modification:

enter image description here

After doing the above, I would again normally select that a tag then the dropdown will automatically stay as-is even when I mouseover to other places like Inspect Element, etc.

You can just refresh the browser when doing inspecting the menu dropdown elements to go back to normal state.

Hope this helps. :)

Coenosarc answered 24/5, 2015 at 3:48 Comment(0)
D
15

You can also do this in the javascript console:

$('#foo').trigger('mouseover');

An that will "freeze" the element in the "hover" state.

Dissatisfactory answered 3/2, 2016 at 21:51 Comment(0)
J
11
  1. Open Inspect element

enter image description here

  1. Now go to elements now on right side and select hover

enter image description here

It will show all hover effects

Justifier answered 25/8, 2021 at 15:36 Comment(0)
M
9

Here's how I do it with no CSS changes or JS pausing in Chrome (I am on a Mac and do not have a PC in front of me if you are running on Win):

  1. have your developer console open.
  2. do not enable the hover inspection tool yet, but instead open up your desired sub menu by moving your mouse over it.
  3. hit Command+Shift+C (Mac) or Ctrl+Shift+C (Win/Linux)

now the hover inspection tool will apply to the elements you have opened in your sub-nav.

Mandle answered 9/3, 2017 at 16:45 Comment(0)
D
7

Not sure if it was present in previous browser revisions, but I just found out this extremely simple method.

Open the inspector in chrome or Firefox, right click on the element you are interested in, and select the appropriate option (in this case: hover). This will trigger the associated CSS.

Opening the menu in chromium Opening the same menu in Firefox

Screenshots from Firefox 55 and chromium 61.

Dnieper answered 19/9, 2017 at 11:58 Comment(2)
Sadly it wont work for complex stuff on :hovered elements. It only triggers the CSS pseudo-class state. Effectively enabling the css involved. But it doesnt trigger the javascript event. The original question was about to be able to debug in such a scenario. See my comment in the most upvoted answer (not the accepted one), for further tips on how to do it in Chrome and Firefox.Add
In Firefox Inspector I right mouse clicked the element and then selected Change Pseudo -class > hoverSainfoin
Y
3

I needed to do this, but the element I was trying to inspect was added and removed dynamically based on hover state of another element. My solution is similar to this one, but that didn't quite work for me.

So here's what I did:

  1. Add simple script to enter debugger mode upon mouseover of the element that triggers the hover event you're concerned about.
$(document).on('mouseover', '[your-hover-element-selector]', function(e) {
  debugger;
});
  1. Then, with the dev console open in Chrome, hover over your element, and you will enter debugger mode. Navigate over to the sources section of the dev tools, and click the "Resume script execution" button (the blue play-like button below).

enter image description here

Once you do that, your DOM will be paused in the hover state, and you can use the element inspector to inspect all the elements as they exist in that state.

Yeta answered 19/4, 2020 at 7:3 Comment(0)
A
3

I found a very simple way to do this if for some reason you have problems with script pausing:

  1. Open Dev Tools on "inspect"-tab.
  2. Hover to make the pop-up appear.
  3. Right-click on the desired element in your pop-up and press 'Q' (in Firefox) to inspect that element.
  4. Use keyboard to navigate:
    • Arrow Up/Down: Move between elements
    • Arrow Left/Right: Collapse/Expand
    • Tab/Shift+Tab: Move between inspector and CSS rules and inside CSS Rules
    • Enter: Edit CSS Rule
Abagail answered 10/12, 2020 at 12:20 Comment(0)
T
2

Excellent stuff!

Thank you to gmo for that advice. I did not know about those attribute settings massively helpful.

As a small revision to the wording I would explain that process as follows:

  • Right Click on the element you would like to style

    • Open 'Inspect' tool

    • On right hand side, navigate to the small Styles tab

    • Found above CSS stylesheet contents

    • Select the .hov option - This will give you all the settings available for the selected HTML element

    • Click and Change all options to be inactive

    • Now Select the state that you would like to tweak - On activation of any of these, your Stylesheet will jump you directly to those settings:

Styles - Tweaking Filters - Interactive elements

This information was a lifesaver for me, cannot believe I have just heard about it!

Terbecki answered 8/7, 2017 at 9:27 Comment(2)
This was the best way for chrome!Spanker
Great, was my response helpful to you?Terbecki
C
0

I used a method where I selected inspect, used the select element, selected said element on the screen, and the title that was on the hover text was the title of the given element. Hope this helps.

Clime answered 27/3, 2023 at 20:47 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Erma
M
-1

Change the CSS so that the property which hides the menu isn't applied while you work on it is what I do.

Megargee answered 11/7, 2013 at 20:36 Comment(2)
Oh come on chap I did specifically say without making such a modification.Inhabit
you said so it doesn't "stay popped up once activated" I am suggesting that remove all activation triggers so it is always visible. that is the way I do all popup menus otherwise it is a world of pain. but knock yourself out :)Megargee

© 2022 - 2024 — McMap. All rights reserved.