Inspect hovered element in Chrome?

2020-05-11 03:41发布

问题:

I am trying to view, through Chrome's developer tools, how tooltips are structured on a site. However, even when I am hovered over the item, when I "inspect element", nothing shows for the tooltip in the html. I know I can set the Style to :hover, but I still can't see the html or css of the tooltip.

Any ideas?

回答1:

I actually found a trick to do that with the Twitter Bootstrap tooltips. If you open the dev tools (F12) on another monitor, then hover over the element to bring up the tooltip, right click as if you were to select 'Inspect Element'. Leaving that context menu open, move the focus over to the dev tools. The html for the tooltip should show up next to the element its a tooltip for in the HTML. Then you can look at it as if it were another element. If you go back to Chrome the HTML disappears so just something to be aware of.

Kind of a weird way but it worked for me so I figured I would share it.



回答2:

This solution works without any extra code.

Hit command-option-j to open the console. Click the window-looking button on the top right corner of the console to open the console in a different window.

Then, in the Chrome window, hover over the element that triggers the popover, hit command-` however many times you need to focus on the console, then type debugger. That'll freeze the page, then you can inspect the element in the Elements tab.



回答3:

F8 will pause debugging.

Mouse over the tooltip, and press F8 while it is displayed.

You can now use the inspector to look at the CSS.



回答4:

You would just need to force the tooltip to show as such

$('.myelement').tooltip('open');

Now the tooltip will show regardless of hovering state.

Scroll down near the bottom of the DOM where you should see the markup.

Update see cneuro's comment for Bootstrap 3.

$('.myelement').tooltip('show');

Update see Marko Grešak's answer for Chrome and apparently Safari as well, $0 can be used as a shortcut for the currently selected element. This appears to work in Safari as well.

$($0).tooltip('show')


回答5:

Click f12 go to the console tab and add the following:

setTimeout(()=> {debugger},5000)

This will give you 5 seconds to do whatever you want and it will break at 5 seconds. Then you can inspect the target element

(ex. hover the element and wait 5 seconds then inspect..)



回答6:

For me, the accepted answer didn't work: clicking in DevTools immediately closed the ToolTip.

However, I found https://superuser.com/questions/249050/chrome-keyboard-shortcut-to-pause-script-execution which helped me:

  1. In the console:, Run: window.addEventListener('keydown', function(e) { if (e.keyCode == 123) debugger; });
  2. Highlight element with inspector

  3. Hit F12

You can now inspect the element, with JavaScript paused so the DOM won't change.



回答7:

Single window answer, with no coding

None of the other answers are quite right, or have enough detail, so here's my attempt.

  • Open Chrome's DevTools using F12/Ctrl+Shift+I (Windows/Linux) or Command+Option+I (Mac).
  • Select the Sources tab in the DevTools window.
  • Using the mouse, hover over the element you want to inspect, to make the tooltip visible.
  • Press F8 (Windows/Linux/Mac) to pause script execution. The main window will grey out, and a "Paused in debugger" popup will appear.
  • In the DevTools window, select the Elements tab
  • For Bootstrap tooltips, the tooltip will appear as the last <div> in the <body>


回答8:

No code solution for JS activated tooltips:

With Chrome's devtools inspect the containing / parent element of the tooltip. In the "elements" tab, right click on that container DOM element then choose "break on" > "subtree modifications". The next time you hover over the part of the DOM the tooltip is housed in, the JS code will be paused allowing you to inspect the contents of the tooltip.



回答9:

Follow these steps

  1. Open Inspect window in chrome.

  2. Place the mouse over the tooltip.

  3. Press F8

    JS execution will be paused and then you can inspect the tooltip.

  4. Press F8 again to start execution and F10 to debug.



回答10:

Here’s a simple solution: If you have dynamic tooltips, you can make them “persistent” by (temporarily) changing the trigger event to click. This will have the effect that the tooltip only disappears on a click-out:

$('body').tooltip({
    selector: "[data-toggle='tooltip']",
    trigger: "click"
});

This way, it can be easily inspected with FF’s or Chrome’s debugging tools.



回答11:

1)Open the Inspect window by clicking F12

2)Go to source tab(next to console)

3)Now hover on element to be inspected and keep your mouse over there.

4)Using keyboard(Tab or shift+tab) to move the control to pause button or F8Refer the image

5)When keyboard focus is on Play button. Hit enter. Your hover element will be freezed you can do anything now



回答12:

it is so simple to edit these tooltips.

Step 1: Inspect the element that has the tooltip. Make sure it is highlighted with blue in devtools.

Step 2: right-click on the element (in devtools part) and select: attribute modifications, under Break on

Step 3: Hover over the inspected element and a gray overlay will appear over the site with a small text: Paused in debugger

at the top of your screen

Step 4: Click on the blue arrow until the hover state is selected.

Step 5: Inspect and edit the tooltip



回答13:

I had problems with this so I went to the documentation and inspected the tooltip that is already rendered on the page. That helped me see the dom structure of the tooltip and edit it accordingly.



回答14:

In Chome on Linux this can be achieved for JS generated tooltips such as those for references on WikiPedia by doing the following:

As stated above, open the dev tools using F12. Open them in another window. Highlight the tooltip and click Ctrl-Shift-C (The HTML Inspector). As you move over the tip, the dev window will show the appropriate section.

If you need to keep the tip open when you mouse off it, to be able to inspect it in the other window more thoroughly, then right click on the tooltip and leave the context menu up, and click on the the dev tools window. In this scenario it leaves the tip up in the wikipedia window.

To a degree it also works with bootstrap tips.



回答15:

For some reason the answers provided here weren't working for me on Windows. I was able to inspect the tooltip by opening the dev tools, then hovering over the element that brings up the tooltip, then right clicking on that element (not the tooltip). Then, move the cursor over into the inspector panel and scroll down to the bottom. The tooltip element should still be there.



回答16:

The dev tools provides a way to inspect a hovered element like a tooltip.

1 - Open the dev tools using F12.

2 - Select "Elements" tab.

3 - Select the parent element that contains the tooltip.

4 - Click on "..." (on the line of the parent element) and after select "Break on"/"subtree modifications" (see image below)

5 - Finally go back to application and make the Tooltip shows up. It should block the execution after the Tooltip gets visible

Hope it can be useful for someone!



回答17:

Worth noting that toggling the :hover state from within the dev tools only has an impact if the hint text is enabled via CSS :hover rules in the first place. The toggle only applies the hover state to the element for rendering purposes, but does not trigger a corresponding JavaScript mouseover event.

Many frameworks such as AngularJS dynamically attach tooltip HTML to the bottom of the document body via JavaScript when a target element is hovered, so any amount of hovering and inspecting the target element won't help.

@joeyyang's answer worked very well for me in this scenario.



回答18:

One of the easiest ways I found is:

  1. Open Chrome dev tools on the side

  2. Hover over element

  3. Right-click

  4. Click on dev tools

  5. Now you can inspect and change styles