188

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?

2
  • 3
    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.
    – jbabey
    Jul 11, 2013 at 20:17
  • 1
    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.
    – Dhanuka777
    Jun 24, 2016 at 0:57

12 Answers 12

304

If the hover element is triggered by JS (if triggered by CSS :hover, see gmo's answer), you can inspect it if you pause script execution. This is a much simpler way of freezing the DOM than the other answers suggest. You can pause script execution without losing the hover element as follows:

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, inspect the DOM, whatever. 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 debugger statement while the hover is open:

  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.

10
  • 3
    The other methods offered here don't work in a lot of contexts where this does.
    – Ed Staub
    Jun 21, 2017 at 20:31
  • 1
    for Safari it's Debugger tab Dec 11, 2017 at 16:44
  • 9
    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. Apr 24, 2018 at 4:54
  • 1
    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!
    – Kitson
    Oct 16, 2019 at 10:39
  • 2
    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.
    – Kir Kanos
    Sep 9, 2020 at 21:02
90

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.

4
  • 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... Feb 9, 2017 at 11:57
  • 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-menu Mar 16, 2018 at 18:39
  • @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. May 28, 2019 at 15:14
  • Seems like at moment the :hover option is in Toggle Classes Option Jun 8, 2019 at 14:02
57

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. :)

0
15

You can also do this in the javascript console:

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

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

0
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

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.

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.

2
  • 1
    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.
    – Kir Kanos
    Sep 9, 2020 at 21:08
  • In Firefox Inspector I right mouse clicked the element and then selected Change Pseudo -class > hover
    – Nick W
    Oct 1, 2021 at 12:25
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.

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

0
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!

2
  • This was the best way for chrome!
    – whisk
    Dec 5, 2018 at 21:24
  • 1
    Great, was my response helpful to you? Dec 6, 2018 at 22:46
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.

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.
    – Community Bot
    Apr 2 at 10:02
-1

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

2
  • Oh come on chap I did specifically say without making such a modification.
    – OJFord
    Jul 12, 2013 at 0:26
  • 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 :)
    – Woody
    Jul 12, 2013 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.